From 1313677a56eae7f23bdad74512f61beca568d477 Mon Sep 17 00:00:00 2001 From: mrq Date: Sat, 29 Aug 2020 00:00:00 -0500 Subject: [PATCH] Commit for 2020.08.29.7z --- bin/data/shaders/display.subpass.frag.glsl | 11 + engine/inc/uf/ext/vulkan/graphic.old.h | 86 ---- engine/inc/uf/ext/vulkan/graphics/base.h | 61 --- engine/inc/uf/ext/vulkan/graphics/compute.h | 79 --- .../ext/vulkan/graphics/deferredrendering.h | 39 -- .../inc/uf/ext/vulkan/graphics/rendertarget.h | 48 -- .../inc/uf/ext/vulkan/rendermodes/deferred.h | 2 +- .../uf/ext/vulkan/rendermodes/rendertarget.h | 2 +- .../rendermodes/stereoscopic_deferred.h | 2 +- engine/src/ext/vulkan/graphic.old.cpp | 245 ---------- engine/src/ext/vulkan/graphics/base.cpp | 316 ------------ .../ext/vulkan/graphics/deferredrendering.cpp | 333 ------------- .../src/ext/vulkan/graphics/rendertarget.cpp | 453 ------------------ .../src/ext/vulkan/rendermodes/deferred.cpp | 35 +- .../ext/vulkan/rendermodes/rendertarget.cpp | 27 -- .../rendermodes/stereoscopic_deferred.cpp | 171 ------- engine/src/ext/vulkan/rendertarget.cpp | 2 +- engine/src/utils/string/ext.cpp | 20 +- ext/gui/gui.cpp | 2 +- ext/main.cpp | 2 +- ext/scenes/world/gui/battle.cpp | 2 +- ext/scenes/world/gui/dialogue.cpp | 2 +- ext/scenes/world/gui/pause.cpp | 2 +- ext/scenes/world/housamo/battle.cpp | 2 +- ext/scenes/world/housamo/dialogue.cpp | 2 +- ext/scenes/world/housamo/sprite.cpp | 2 +- ext/scenes/world/light/light.cpp | 96 ++++ ext/scenes/world/light/light.h | 16 + ext/scenes/world/portal/portal.cpp | 2 +- ext/scenes/world/terrain/generator.cpp | 112 ----- ext/scenes/world/terrain/generator.h | 4 +- ext/scenes/world/terrain/terrain.cpp | 2 +- ext/scenes/world/world.cpp | 6 +- 33 files changed, 162 insertions(+), 2024 deletions(-) delete mode 100644 engine/inc/uf/ext/vulkan/graphic.old.h delete mode 100644 engine/inc/uf/ext/vulkan/graphics/base.h delete mode 100644 engine/inc/uf/ext/vulkan/graphics/compute.h delete mode 100644 engine/inc/uf/ext/vulkan/graphics/deferredrendering.h delete mode 100644 engine/inc/uf/ext/vulkan/graphics/rendertarget.h delete mode 100644 engine/src/ext/vulkan/graphic.old.cpp delete mode 100644 engine/src/ext/vulkan/graphics/base.cpp delete mode 100644 engine/src/ext/vulkan/graphics/deferredrendering.cpp delete mode 100644 engine/src/ext/vulkan/graphics/rendertarget.cpp create mode 100644 ext/scenes/world/light/light.cpp create mode 100644 ext/scenes/world/light/light.h diff --git a/bin/data/shaders/display.subpass.frag.glsl b/bin/data/shaders/display.subpass.frag.glsl index e2cabe0d..39df87b0 100644 --- a/bin/data/shaders/display.subpass.frag.glsl +++ b/bin/data/shaders/display.subpass.frag.glsl @@ -3,6 +3,7 @@ layout (input_attachment_index = 0, binding = 1) uniform subpassInput samplerAlbedo; layout (input_attachment_index = 0, binding = 2) uniform subpassInput samplerPosition; layout (input_attachment_index = 0, binding = 3) uniform subpassInput samplerNormal; +layout (input_attachment_index = 0, binding = 4) uniform subpassInput samplerDepth; layout (location = 0) in vec2 inUv; layout (location = 1) in flat uint inPushConstantPass; @@ -82,6 +83,16 @@ void main() { position.eye = subpassLoad(samplerPosition).rgb; normal.eye = subpassLoad(samplerNormal).rgb; + { + float depth = subpassLoad(samplerDepth).r; + mat4 iProj = inverse( ubo.matrices.projection[inPushConstantPass] ); + vec4 positionClip = vec4(inUv * 2.0 - 1.0, depth, 1.0); + positionClip.y *= -1; + vec4 positionEye = iProj * positionClip; + positionEye /= positionEye.w; + position.eye = positionEye.xyz; + } + vec3 fragColor = albedoSpecular.rgb * ubo.ambient.rgb; bool lit = false; for ( uint i = 0; i < LIGHTS; ++i ) { diff --git a/engine/inc/uf/ext/vulkan/graphic.old.h b/engine/inc/uf/ext/vulkan/graphic.old.h deleted file mode 100644 index 3e4c409f..00000000 --- a/engine/inc/uf/ext/vulkan/graphic.old.h +++ /dev/null @@ -1,86 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace ext { - namespace vulkan { - struct RenderMode; - struct UF_API GraphicOld { - VkPipeline pipeline; - VkPipelineLayout pipelineLayout; - VkDescriptorSet descriptorSet; - VkDescriptorSetLayout descriptorSetLayout; - VkDescriptorPool descriptorPool; - - struct { - std::vector modules; - std::vector stages; - } shader; - std::vector buffers; - - Device* device = VK_NULL_HANDLE; - RenderMode* renderMode = VK_NULL_HANDLE; - - bool autoAssigned = false; - bool initialized = false; - bool process = true; - uint32_t subpass = 0; - static VkFrontFace DEFAULT_WINDING_ORDER; - - virtual ~GraphicOld(); - // - template - inline size_t initializeBuffer( T data, VkDeviceSize length, VkBufferUsageFlags usageFlags, VkMemoryPropertyFlags memoryPropertyFlags, bool stage = true ) { - return initializeBuffer( (void*) &data, length, usageFlags, memoryPropertyFlags, stage ); - } - template - inline void updateBuffer( T data, VkDeviceSize length, size_t index = 0, bool stage = true ) { - return updateBuffer( (void*) &data, length, index, stage ); - } - template - inline size_t initializeBuffer( T data, VkBufferUsageFlags usageFlags, VkMemoryPropertyFlags memoryPropertyFlags, bool stage = true ) { - return initializeBuffer( (void*) &data, static_cast(sizeof(T)), usageFlags, memoryPropertyFlags, stage ); - } - template - inline void updateBuffer( T data, size_t index = 0, bool stage = true ) { - return updateBuffer( (void*) &data, static_cast(sizeof(T)), index, stage ); - } - template - inline void updateBuffer( T data, VkDeviceSize length, Buffer& buffer, bool stage = true ) { - return updateBuffer( (void*) &data, length, buffer, stage ); - } - size_t initializeBuffer( void* data, VkDeviceSize length, VkBufferUsageFlags usageFlags, VkMemoryPropertyFlags memoryPropertyFlags, bool stage = true ); - void updateBuffer( void* data, VkDeviceSize length, size_t index = 0, bool stage = true ); - void updateBuffer( void* data, VkDeviceSize length, Buffer& buffer, bool stage = true ); - - void initializeShaders( const std::vector>& ); - - template - inline void initializeDescriptorLayout( const std::vector& setLayoutBindings, const T& t ) { - return initializeDescriptorLayout( setLayoutBindings, sizeof(t) ); - } - void initializeDescriptorLayout( const std::vector& setLayoutBindings, std::size_t = 0 ); - void initializePipeline( VkGraphicsPipelineCreateInfo pipelineCreateInfo ); - void initializeDescriptorPool( const std::vector& poolSize, size_t length ); - void initializeDescriptorSet( const std::vector& writeDescriptorSets ); - - // RAII - virtual void initialize( const std::string& = "" ); - virtual void initialize( Device& device, RenderMode& renderMode ); - virtual void destroy(); - virtual void autoAssign(); - virtual bool autoAssignable() const; - virtual std::string name() const; - // - virtual void render(); - virtual void createCommandBuffer( VkCommandBuffer ); - virtual void createImageMemoryBarrier( VkCommandBuffer ); - virtual void updateDynamicUniformBuffer(bool = false); - }; - } -} diff --git a/engine/inc/uf/ext/vulkan/graphics/base.h b/engine/inc/uf/ext/vulkan/graphics/base.h deleted file mode 100644 index 97425fbb..00000000 --- a/engine/inc/uf/ext/vulkan/graphics/base.h +++ /dev/null @@ -1,61 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -#include - -namespace ext { - namespace vulkan { - struct UF_API GraphicDescriptor { - std::size_t size; // sizeof(Vertex) - std::vector attributes; - uf::Userdata uniforms; - - bool defaultedPushConstants = false; - uf::Userdata pushConstants; - struct { - VkPrimitiveTopology topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; - VkPolygonMode fill = VK_POLYGON_MODE_FILL; - float lineWidth = 1.0f; - VkFrontFace frontFace = ext::vulkan::GraphicOld::DEFAULT_WINDING_ORDER; - } rasterMode; - - }; - struct UF_API BaseGraphic : public GraphicOld { - uint32_t indices = 0; - ext::vulkan::GraphicDescriptor description; - ext::vulkan::Texture2D texture; - // - void describeVertex( const std::vector& ); - template - void bindUniform() { - description.uniforms.create(); - } - template - void bindPushConstants() { - description.pushConstants.create(); - } - template - U& uniforms() { - return description.uniforms.get(); - } - template - U& pushConstants() { - return description.pushConstants.get(); - } - - virtual void createCommandBuffer( VkCommandBuffer ); - virtual bool autoAssignable() const; - virtual std::string name() const; - // RAII - virtual void initialize( const std::string& = "" ); - virtual void initialize( Device& device, RenderMode& renderMode ); - virtual void destroy(); - }; - } -} \ No newline at end of file diff --git a/engine/inc/uf/ext/vulkan/graphics/compute.h b/engine/inc/uf/ext/vulkan/graphics/compute.h deleted file mode 100644 index 4b097f5f..00000000 --- a/engine/inc/uf/ext/vulkan/graphics/compute.h +++ /dev/null @@ -1,79 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace ext { - namespace vulkan { - struct UF_API ComputeGraphic : public GraphicOld { - // alias typedefs - typedef pod::Primitive Cube; - typedef pod::Light Light; - typedef pod::Tree Tree; - - // Uniform buffer - struct { - struct { - alignas(16) pod::Vector3f position = { 0.0f, 0.0f, 0.0f }; - alignas(16) pod::Matrix4f view; - float aspectRatio; // Aspect ratio of the viewport - } camera; - struct { - struct { - uint start = 0; - uint end = std::numeric_limits::max(); - } cubes; - struct { - uint start = 0; - uint end = std::numeric_limits::max(); - } lights; - uint root = std::numeric_limits::max(); - } ssbo; - } uniforms; - - VkQueue queue; // Separate queue for compute commands (queue family may differ from the one used for graphics) - VkCommandPool commandPool; // Use a separate command pool (queue family may differ from the one used for graphics) - VkCommandBuffer commandBuffer; // Command buffer storing the dispatch commands and barriers - VkFence fence; // Synchronization fence to avoid rewriting compute CB if still in use - Texture2D renderTarget; // - Texture2D diffuseTexture; // - - void setStorageBuffers( Device& device, std::vector& cubes, std::vector& lights, std::vector& ); - void updateStorageBuffers( Device& device, std::vector& cubes, std::vector& lights, std::vector& ); - void updateUniformBuffer(); - virtual void createCommandBuffer( VkCommandBuffer ); - virtual std::string name() const; - // RAII - void initialize( Device& device, RenderMode& renderMode, uint32_t width = 0, uint32_t height = 0 ); - virtual void destroy(); - }; - } -} - -namespace ext { - namespace vulkan { - struct UF_API RTGraphic : public GraphicOld { - ComputeGraphic compute; - - uint32_t width = 0; - uint32_t height = 0; - - virtual void createCommandBuffer( VkCommandBuffer ); - virtual void createImageMemoryBarrier( VkCommandBuffer ); - virtual void updateUniformBuffer(); - virtual bool autoAssignable() const; - virtual std::string name() const; - // RAII - virtual void initialize( const std::string& = "" ); - virtual void initialize( Device& device, RenderMode& renderMode ); - virtual void render(); - virtual void destroy(); - }; - } -} \ No newline at end of file diff --git a/engine/inc/uf/ext/vulkan/graphics/deferredrendering.h b/engine/inc/uf/ext/vulkan/graphics/deferredrendering.h deleted file mode 100644 index bfdba622..00000000 --- a/engine/inc/uf/ext/vulkan/graphics/deferredrendering.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -#include - -namespace ext { - namespace vulkan { - struct UF_API DeferredRenderingGraphic : public GraphicOld { - struct Vertex { - pod::Vector2f position; - pod::Vector2f uv; - }; - - static size_t maxLights; - uf::Userdata uniforms; - - struct { - uint32_t pass = 0; - } pushConstants; - - uint32_t indices = 0; - ext::vulkan::RenderTarget* renderTarget; - - virtual void createCommandBuffer( VkCommandBuffer ); - virtual bool autoAssignable() const; - virtual std::string name() const; - // RAII - virtual void initialize( const std::string& = "" ); - virtual void initialize( Device& device, RenderMode& renderMode ); - virtual void destroy(); - }; - } -} \ No newline at end of file diff --git a/engine/inc/uf/ext/vulkan/graphics/rendertarget.h b/engine/inc/uf/ext/vulkan/graphics/rendertarget.h deleted file mode 100644 index 9dc4b3d5..00000000 --- a/engine/inc/uf/ext/vulkan/graphics/rendertarget.h +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -#include - -namespace ext { - namespace vulkan { - struct UF_API RenderTargetGraphic : public GraphicOld { - struct Vertex { - alignas(8) pod::Vector2f position; - alignas(8) pod::Vector2f uv; - }; - - struct { - struct { - alignas(16) pod::Matrix4f models[2]; - } matrices; - struct { - alignas(8) pod::Vector2f position = { 0.5f, 0.5f }; - alignas(8) pod::Vector2f radius = { 0.1f, 0.1f }; - alignas(16) pod::Vector4f color = { 1, 1, 1, 1 }; - } cursor; - alignas(4) float alpha; - } uniforms; - struct { - uint32_t pass = 0; - } pushConstants; - - uint32_t indices = 0; - VkSampler sampler; - ext::vulkan::RenderTarget* renderTarget; - - virtual void createCommandBuffer( VkCommandBuffer ); - virtual bool autoAssignable() const; - virtual std::string name() const; - // RAII - virtual void initialize( const std::string& = "" ); - virtual void initialize( Device& device, RenderMode& renderMode ); - virtual void destroy(); - }; - } -} \ No newline at end of file diff --git a/engine/inc/uf/ext/vulkan/rendermodes/deferred.h b/engine/inc/uf/ext/vulkan/rendermodes/deferred.h index 377b49f1..2ad5a5c4 100644 --- a/engine/inc/uf/ext/vulkan/rendermodes/deferred.h +++ b/engine/inc/uf/ext/vulkan/rendermodes/deferred.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include namespace ext { namespace vulkan { diff --git a/engine/inc/uf/ext/vulkan/rendermodes/rendertarget.h b/engine/inc/uf/ext/vulkan/rendermodes/rendertarget.h index 49651d98..fc1fe087 100644 --- a/engine/inc/uf/ext/vulkan/rendermodes/rendertarget.h +++ b/engine/inc/uf/ext/vulkan/rendermodes/rendertarget.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include namespace ext { namespace vulkan { diff --git a/engine/inc/uf/ext/vulkan/rendermodes/stereoscopic_deferred.h b/engine/inc/uf/ext/vulkan/rendermodes/stereoscopic_deferred.h index 65c822ae..89392af7 100644 --- a/engine/inc/uf/ext/vulkan/rendermodes/stereoscopic_deferred.h +++ b/engine/inc/uf/ext/vulkan/rendermodes/stereoscopic_deferred.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include namespace ext { namespace vulkan { diff --git a/engine/src/ext/vulkan/graphic.old.cpp b/engine/src/ext/vulkan/graphic.old.cpp deleted file mode 100644 index 82b7e28a..00000000 --- a/engine/src/ext/vulkan/graphic.old.cpp +++ /dev/null @@ -1,245 +0,0 @@ -#include -#include -#include -#include - -VkFrontFace ext::vulkan::GraphicOld::DEFAULT_WINDING_ORDER = VK_FRONT_FACE_CLOCKWISE; - -// Buffers -size_t ext::vulkan::GraphicOld::initializeBuffer( void* data, VkDeviceSize length, VkBufferUsageFlags usageFlags, VkMemoryPropertyFlags memoryPropertyFlags, bool stage ) { - Buffer buffer; - - if ( autoAssignable() ) autoAssign(); - - // Stage - if ( !stage ) { - VK_CHECK_RESULT(device->createBuffer( - usageFlags, - memoryPropertyFlags, - buffer, - length - )); - size_t index = buffers.size(); - buffers.push_back( std::move(buffer) ); - this->updateBuffer( data, length, index, stage ); - return index; - } - - VkQueue queue = device->graphicsQueue; - Buffer staging; - VkDeviceSize storageBufferSize = length; - device->createBuffer( - VK_BUFFER_USAGE_TRANSFER_SRC_BIT, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, - staging, - storageBufferSize, - data - ); - - device->createBuffer( - usageFlags, - memoryPropertyFlags, - buffer, - storageBufferSize - ); - - // Copy to staging buffer - VkCommandBuffer copyCmd = device->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); - VkBufferCopy copyRegion = {}; - copyRegion.size = storageBufferSize; - vkCmdCopyBuffer(copyCmd, staging.buffer, buffer.buffer, 1, ©Region); - device->flushCommandBuffer(copyCmd, queue, true); - staging.destroy(); - - size_t index = buffers.size(); - buffers.push_back( std::move(buffer) ); - return index; -} -void ext::vulkan::GraphicOld::updateBuffer( void* data, VkDeviceSize length, size_t index, bool stage ) { - Buffer& buffer = buffers.at(index); - return updateBuffer( data, length, buffer, stage ); -} -void ext::vulkan::GraphicOld::updateBuffer( void* data, VkDeviceSize length, Buffer& buffer, bool stage ) { - if ( !stage ) { - VK_CHECK_RESULT(buffer.map()); - memcpy(buffer.mapped, data, length); - buffer.unmap(); - return; - } - VkQueue queue = device->graphicsQueue; - Buffer staging; - device->createBuffer( - VK_BUFFER_USAGE_TRANSFER_SRC_BIT, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, - staging, - length, - data - ); - - // Copy to staging buffer - VkCommandBuffer copyCmd = device->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); - VkBufferCopy copyRegion = {}; - copyRegion.size = length; - vkCmdCopyBuffer(copyCmd, staging.buffer, buffer.buffer, 1, ©Region); - device->flushCommandBuffer(copyCmd, queue, true); - staging.destroy(); -} -// Set shaders -void ext::vulkan::GraphicOld::initializeShaders( const std::vector>& layout ) { - if ( !device ) device = &ext::vulkan::device; - shader.stages.clear(); - shader.modules.clear(); - shader.stages.reserve( layout.size() ); - for ( auto& pair : layout ) { - shader.stages.push_back(loadShader(pair.first, pair.second, device->logicalDevice, shader.modules)); - } -} -// Set Descriptor Layout -void ext::vulkan::GraphicOld::initializeDescriptorLayout( const std::vector& setLayoutBindings, std::size_t pushConstantSize ) { - VkDescriptorSetLayoutCreateInfo descriptorLayout = ext::vulkan::initializers::descriptorSetLayoutCreateInfo( - setLayoutBindings.data(), - static_cast(setLayoutBindings.size()) - ); - - VK_CHECK_RESULT(vkCreateDescriptorSetLayout(*device, &descriptorLayout, nullptr, &descriptorSetLayout)); - - VkPipelineLayoutCreateInfo pPipelineLayoutCreateInfo = ext::vulkan::initializers::pipelineLayoutCreateInfo( - &descriptorSetLayout, - 1 - ); - - VkPushConstantRange pushConstantRange = {}; - if ( pushConstantSize > 0 ) { - pushConstantRange = ext::vulkan::initializers::pushConstantRange( - VK_SHADER_STAGE_VERTEX_BIT, - pushConstantSize, - 0 - ); - // Push constant ranges are part of the pipeline layout - pPipelineLayoutCreateInfo.pushConstantRangeCount = 1; - pPipelineLayoutCreateInfo.pPushConstantRanges = &pushConstantRange; - } - - VK_CHECK_RESULT(vkCreatePipelineLayout(*device, &pPipelineLayoutCreateInfo, nullptr, &pipelineLayout)); -} -// Create pipeline -void ext::vulkan::GraphicOld::initializePipeline( VkGraphicsPipelineCreateInfo pipelineCreateInfo ) { - // ext::vulkan::mutex.lock(); - - pipelineCreateInfo.subpass = this->subpass; - VK_CHECK_RESULT(vkCreateGraphicsPipelines(*device, device->pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipeline)); - - // ext::vulkan::mutex.unlock(); -} -// Set descriptor pool -void ext::vulkan::GraphicOld::initializeDescriptorPool( const std::vector& poolSizes, size_t length ) { - VkDescriptorPoolCreateInfo descriptorPoolInfo = ext::vulkan::initializers::descriptorPoolCreateInfo( - static_cast(poolSizes.size()), - const_cast(poolSizes.data()), - length - ); - - VK_CHECK_RESULT(vkCreateDescriptorPool(*device, &descriptorPoolInfo, nullptr, &descriptorPool)); - - VkDescriptorSetAllocateInfo allocInfo = ext::vulkan::initializers::descriptorSetAllocateInfo( - descriptorPool, - &descriptorSetLayout, - 1 - ); - - VK_CHECK_RESULT(vkAllocateDescriptorSets(*device, &allocInfo, &descriptorSet)); -} -// Set descriptor set -void ext::vulkan::GraphicOld::initializeDescriptorSet( const std::vector& writeDescriptorSets ) { - vkUpdateDescriptorSets( - *device, - static_cast(writeDescriptorSets.size()), - writeDescriptorSets.data(), - 0, - NULL - ); -} - -bool ext::vulkan::GraphicOld::autoAssignable() const { - return false; -} -void ext::vulkan::GraphicOld::autoAssign() { - if ( !autoAssigned ) { - ext::vulkan::rebuild = true; -/* - ext::vulkan::graphicOlds->push_back(this); -*/ - } - autoAssigned = true; -} -std::string ext::vulkan::GraphicOld::name() const { - return "Graphic"; -} - -void ext::vulkan::GraphicOld::initialize( const std::string& renderMode ) { - return initialize(this->device ? *device : ext::vulkan::device, ext::vulkan::getRenderMode(renderMode)); -} -void ext::vulkan::GraphicOld::initialize( Device& device, RenderMode& renderMode ) { - this->device = &device; - this->renderMode = &renderMode; - this->initialized = true; - if ( autoAssignable() ) autoAssign(); -} -ext::vulkan::GraphicOld::~GraphicOld() { - this->destroy(); -} -void ext::vulkan::GraphicOld::destroy() { - for (auto& buffer : buffers) { - buffer.destroy(); - } - if ( autoAssigned ) { -/* - ext::vulkan::graphicOlds->erase( - std::remove(ext::vulkan::graphicOlds->begin(), ext::vulkan::graphicOlds->end(), this), - ext::vulkan::graphicOlds->end() - ); -*/ - autoAssigned = false; - ext::vulkan::rebuild = true; - } - initialized = false; - if ( !device || device == VK_NULL_HANDLE ) return; - if ( descriptorPool != VK_NULL_HANDLE) { - vkDestroyDescriptorPool( *device, descriptorPool, nullptr ); - descriptorPool = VK_NULL_HANDLE; - } - if ( pipelineLayout != VK_NULL_HANDLE ) { - vkDestroyPipelineLayout( *device, pipelineLayout, nullptr ); - pipelineLayout = VK_NULL_HANDLE; - } - if ( pipeline != VK_NULL_HANDLE ) { - vkDestroyPipeline( *device, pipeline, nullptr ); - pipeline = VK_NULL_HANDLE; - } - if ( descriptorSetLayout != VK_NULL_HANDLE ) { - vkDestroyDescriptorSetLayout( *device, descriptorSetLayout, nullptr ); - descriptorSetLayout = VK_NULL_HANDLE; - } - for ( auto& module : shader.modules ) { - if ( module != VK_NULL_HANDLE ) { - vkDestroyShaderModule( *device, module, nullptr ); - module = VK_NULL_HANDLE; - } - } - shader.modules.clear(); - shader.stages.clear(); - buffers.clear(); -} -/* -bool ext::vulkan::GraphicOld::autoAssignable() { - return false; -} -*/ -void ext::vulkan::GraphicOld::render() { -} -void ext::vulkan::GraphicOld::createCommandBuffer( VkCommandBuffer commandBuffer ) { -} -void ext::vulkan::GraphicOld::createImageMemoryBarrier( VkCommandBuffer commandBuffer ) { -} -void ext::vulkan::GraphicOld::updateDynamicUniformBuffer( bool force ) { -} \ No newline at end of file diff --git a/engine/src/ext/vulkan/graphics/base.cpp b/engine/src/ext/vulkan/graphics/base.cpp deleted file mode 100644 index b1210422..00000000 --- a/engine/src/ext/vulkan/graphics/base.cpp +++ /dev/null @@ -1,316 +0,0 @@ -#include -#include -#include -#include -#include - -namespace { - uint32_t VERTEX_BUFFER_BIND_ID = 0; - struct PushConstants { - uint32_t pass = 0; - }; -} -bool ext::vulkan::BaseGraphic::autoAssignable() const { - return false; -} -std::string ext::vulkan::BaseGraphic::name() const { - return "BaseGraphic"; -} -void ext::vulkan::BaseGraphic::createCommandBuffer( VkCommandBuffer commandBuffer ) { - assert( buffers.size() >= 2 ); - Buffer& vertexBuffer = buffers.at(1); - Buffer& indexBuffer = buffers.at(2); - - if ( description.pushConstants.initialized() ) { - // Bind push constants - pod::Userdata& userdata = description.pushConstants.data(); - if ( description.defaultedPushConstants ) pushConstants() = { ext::openvr::renderPass }; - vkCmdPushConstants( commandBuffer, pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, userdata.len, userdata.data ); - } - - // Bind descriptor sets describing shader binding points - vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, nullptr); - // Bind the rendering pipeline - // The pipeline (state object) contains all states of the rendering pipeline, binding it will set all the states specified at pipeline creation time - vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); - // Bind triangle vertex buffer (contains position and colors) - VkDeviceSize offsets[1] = { 0 }; - vkCmdBindVertexBuffers(commandBuffer, 0, 1, &vertexBuffer.buffer, offsets); - // Bind triangle index buffer - vkCmdBindIndexBuffer(commandBuffer, indexBuffer.buffer, 0, VK_INDEX_TYPE_UINT32); - // Draw indexed triangle - vkCmdDrawIndexed(commandBuffer, static_cast(indices), 1, 0, 0, 1); - - // std::cout << this << ": " << descriptorSet << std::endl; -} -void ext::vulkan::BaseGraphic::describeVertex( const std::vector& descriptor ) { - description.attributes = descriptor; -} -void ext::vulkan::BaseGraphic::initialize( const std::string& renderMode ) { - return initialize(this->device ? *device : ext::vulkan::device, ext::vulkan::getRenderMode(renderMode)); -} -void ext::vulkan::BaseGraphic::initialize( Device& device, RenderMode& renderMode ) { - // asset correct buffer sizes - assert( buffers.size() >= 2 ); - ext::vulkan::GraphicOld::initialize( device, renderMode ); - - // create default push constant - if ( !description.pushConstants.initialized() ) { - // || description.pushConstants.data().len > device.properties.limits.maxPushConstantsSize ) { - description.defaultedPushConstants = true; - bindPushConstants(); - pushConstants() = { 0 }; - - } - if ( description.pushConstants.initialized() ) { - // set descriptor layout - assert( description.pushConstants.data().len <= device.properties.limits.maxPushConstantsSize ); - } - - initializeDescriptorLayout({ - // Vertex shader - ext::vulkan::initializers::descriptorSetLayoutBinding( - VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - VK_SHADER_STAGE_VERTEX_BIT, - 0 - ), - // Fragment shader - ext::vulkan::initializers::descriptorSetLayoutBinding( - VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, - VK_SHADER_STAGE_FRAGMENT_BIT, - 1 - ) - }, description.pushConstants.data().len); - // Create uniform buffer - pod::Userdata& userdata = description.uniforms.data(); - initializeBuffer( - (void*) userdata.data, - userdata.len, - VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, - false - ); - // Move uniform buffer to the front - { - for ( auto it = buffers.begin(); it != buffers.end(); ++it ) { - Buffer& buffer = *it; - if ( !(buffer.usageFlags & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) ) continue; - Buffer uniformBuffer = std::move(buffer); - buffers.erase(it); - buffers.insert( buffers.begin(), std::move(uniformBuffer) ); - break; - } - } -/* - buffers = { - std::move(buffers.at(2)), - std::move(buffers.at(0)), - std::move(buffers.at(1)), - }; -*/ - // set pipeline - { - VkPipelineInputAssemblyStateCreateInfo inputAssemblyState = ext::vulkan::initializers::pipelineInputAssemblyStateCreateInfo( - this->description.rasterMode.topology, - 0, - VK_FALSE - ); - VkPipelineRasterizationStateCreateInfo rasterizationState = ext::vulkan::initializers::pipelineRasterizationStateCreateInfo( - this->description.rasterMode.fill, - VK_CULL_MODE_BACK_BIT, - // VK_CULL_MODE_NONE, - this->description.rasterMode.frontFace, - 0 - ); - rasterizationState.lineWidth = this->description.rasterMode.lineWidth; - /* - VkPipelineColorBlendAttachmentState blendAttachmentState = ext::vulkan::initializers::pipelineColorBlendAttachmentState( - VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT, - VK_FALSE - ); - blendAttachmentState.blendEnable = VK_TRUE; - blendAttachmentState.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; - blendAttachmentState.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; - blendAttachmentState.colorBlendOp = VK_BLEND_OP_ADD; - blendAttachmentState.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; - blendAttachmentState.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; - blendAttachmentState.alphaBlendOp = VK_BLEND_OP_ADD; - VkPipelineColorBlendStateCreateInfo colorBlendState = ext::vulkan::initializers::pipelineColorBlendStateCreateInfo( - 1, - &blendAttachmentState - ); - */ - /* - VkPipelineColorBlendAttachmentState blendAttachmentState = ext::vulkan::initializers::pipelineColorBlendAttachmentState( - 0xf, - VK_FALSE - ); - VkPipelineColorBlendStateCreateInfo colorBlendState = ext::vulkan::initializers::pipelineColorBlendStateCreateInfo( - 1, - &blendAttachmentState - ); - */ - - std::vector blendAttachmentStates; - if ( renderMode.getType() == "Swapchain" ) { - VkPipelineColorBlendAttachmentState blendAttachmentState = ext::vulkan::initializers::pipelineColorBlendAttachmentState( - 0xf, - VK_TRUE - ); - blendAttachmentState.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; - blendAttachmentState.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; - blendAttachmentState.colorBlendOp = VK_BLEND_OP_ADD; - blendAttachmentState.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; - blendAttachmentState.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; - blendAttachmentState.alphaBlendOp = VK_BLEND_OP_ADD; - blendAttachmentStates.push_back(blendAttachmentState); - } else { - auto& subpass = renderMode.renderTarget.passes[this->subpass]; - for ( auto& input : subpass.colors ) { - VkPipelineColorBlendAttachmentState blendAttachmentState = ext::vulkan::initializers::pipelineColorBlendAttachmentState( - 0xf, - VK_TRUE - ); - blendAttachmentState.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; - blendAttachmentState.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; - blendAttachmentState.colorBlendOp = VK_BLEND_OP_ADD; - blendAttachmentState.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; - blendAttachmentState.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; - blendAttachmentState.alphaBlendOp = VK_BLEND_OP_ADD; - blendAttachmentStates.push_back(blendAttachmentState); - } - } - // std::cout << blendAttachmentStates.size() << ": " << renderMode.getType() << std::endl; - VkPipelineColorBlendStateCreateInfo colorBlendState = ext::vulkan::initializers::pipelineColorBlendStateCreateInfo( - blendAttachmentStates.size(), - blendAttachmentStates.data() - ); - /* - colorBlendState.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; - colorBlendState.logicOpEnable = VK_FALSE; - colorBlendState.logicOp = VK_LOGIC_OP_COPY; - colorBlendState.blendConstants[0] = 0.0f; - colorBlendState.blendConstants[1] = 0.0f; - colorBlendState.blendConstants[2] = 0.0f; - colorBlendState.blendConstants[3] = 0.0f; - */ - VkPipelineDepthStencilStateCreateInfo depthStencilState = ext::vulkan::initializers::pipelineDepthStencilStateCreateInfo( - VK_TRUE, - VK_TRUE, - //VK_COMPARE_OP_LESS_OR_EQUAL - VK_COMPARE_OP_GREATER_OR_EQUAL - ); - VkPipelineViewportStateCreateInfo viewportState = ext::vulkan::initializers::pipelineViewportStateCreateInfo( - 1, 1, 0 - ); - VkPipelineMultisampleStateCreateInfo multisampleState = ext::vulkan::initializers::pipelineMultisampleStateCreateInfo( - VK_SAMPLE_COUNT_1_BIT, - 0 - ); - std::vector dynamicStateEnables = { - VK_DYNAMIC_STATE_VIEWPORT, - VK_DYNAMIC_STATE_SCISSOR - }; - VkPipelineDynamicStateCreateInfo dynamicState = ext::vulkan::initializers::pipelineDynamicStateCreateInfo( - dynamicStateEnables.data(), - static_cast(dynamicStateEnables.size()), - 0 - ); - - // Binding description - std::vector vertexBindingDescriptions = { - ext::vulkan::initializers::vertexInputBindingDescription( - VERTEX_BUFFER_BIND_ID, - description.size, - VK_VERTEX_INPUT_RATE_VERTEX - ) - }; - // Attribute descriptions - // Describes memory layout and shader positions - std::vector vertexAttributeDescriptions = {}; - for ( auto& descriptor : description.attributes ) { - auto d = ext::vulkan::initializers::vertexInputAttributeDescription( - VERTEX_BUFFER_BIND_ID, - vertexAttributeDescriptions.size(), - descriptor.format, - descriptor.offset - ); - vertexAttributeDescriptions.push_back(d); - } - - VkPipelineVertexInputStateCreateInfo vertexInputState = ext::vulkan::initializers::pipelineVertexInputStateCreateInfo(); - vertexInputState.vertexBindingDescriptionCount = static_cast(vertexBindingDescriptions.size()); - vertexInputState.pVertexBindingDescriptions = vertexBindingDescriptions.data(); - vertexInputState.vertexAttributeDescriptionCount = static_cast(vertexAttributeDescriptions.size()); - vertexInputState.pVertexAttributeDescriptions = vertexAttributeDescriptions.data(); - - VkGraphicsPipelineCreateInfo pipelineCreateInfo = ext::vulkan::initializers::pipelineCreateInfo( - pipelineLayout, - renderMode.renderTarget.renderPass, - 0 - ); - - pipelineCreateInfo.pVertexInputState = &vertexInputState; - pipelineCreateInfo.pInputAssemblyState = &inputAssemblyState; - pipelineCreateInfo.pRasterizationState = &rasterizationState; - pipelineCreateInfo.pColorBlendState = &colorBlendState; - pipelineCreateInfo.pMultisampleState = &multisampleState; - pipelineCreateInfo.pViewportState = &viewportState; - pipelineCreateInfo.pDepthStencilState = &depthStencilState; - pipelineCreateInfo.pDynamicState = &dynamicState; - pipelineCreateInfo.stageCount = static_cast(shader.stages.size()); - pipelineCreateInfo.pStages = shader.stages.data(); - pipelineCreateInfo.subpass = this->subpass; - - initializePipeline(pipelineCreateInfo); - } - // Set descriptor pool - initializeDescriptorPool({ - ext::vulkan::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1), - ext::vulkan::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1) - }, 1); - // Set descriptor set - { - std::vector writeDescriptorSets = { - // Binding 0 : Projection/View matrix uniform buffer - ext::vulkan::initializers::writeDescriptorSet( - descriptorSet, - VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - 0, - &(buffers.at(0).descriptor) - ) - }; - if ( texture.generated() ) - writeDescriptorSets.push_back(ext::vulkan::initializers::writeDescriptorSet( - descriptorSet, - VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, - 1, - &texture.descriptor - )); - initializeDescriptorSet(writeDescriptorSets); - } -/* - initializeDescriptorSet({ - // Binding 0 : Projection/View matrix uniform buffer - ext::vulkan::initializers::writeDescriptorSet( - descriptorSet, - VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - 0, - &(buffers.at(0).descriptor) - ), - // Binding 1 : Fragment shader texture sampler - // Fragment shader: layout (binding = 1) uniform sampler2D samplerColor; - ext::vulkan::initializers::writeDescriptorSet( - descriptorSet, - VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, - 1, - &texture.descriptor - ) - }); -*/ -} -void ext::vulkan::BaseGraphic::destroy() { - texture.destroy(); - shader.stages.clear(); - ext::vulkan::GraphicOld::destroy(); -} \ No newline at end of file diff --git a/engine/src/ext/vulkan/graphics/deferredrendering.cpp b/engine/src/ext/vulkan/graphics/deferredrendering.cpp deleted file mode 100644 index 41bd03d5..00000000 --- a/engine/src/ext/vulkan/graphics/deferredrendering.cpp +++ /dev/null @@ -1,333 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -namespace { - uint32_t VERTEX_BUFFER_BIND_ID = 0; - float r() { - return (rand() % 100) / 100.0; - } -} - -size_t ext::vulkan::DeferredRenderingGraphic::maxLights = 32; - -bool ext::vulkan::DeferredRenderingGraphic::autoAssignable() const { - return false; -} -std::string ext::vulkan::DeferredRenderingGraphic::name() const { - return "DeferredRenderingGraphic"; -} -void ext::vulkan::DeferredRenderingGraphic::createCommandBuffer( VkCommandBuffer commandBuffer ) { - assert( buffers.size() >= 2 ); - Buffer& vertexBuffer = buffers.at(1); - Buffer& indexBuffer = buffers.at(2); - - pushConstants = { ext::openvr::renderPass }; - vkCmdPushConstants( commandBuffer, pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(pushConstants), &pushConstants ); - // Bind descriptor sets describing shader binding points - vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, nullptr); - // Bind the rendering pipeline - // The pipeline (state object) contains all states of the rendering pipeline, binding it will set all the states specified at pipeline creation time - vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); - // Bind triangle vertex buffer (contains position and colors) - VkDeviceSize offsets[1] = { 0 }; - vkCmdBindVertexBuffers(commandBuffer, 0, 1, &vertexBuffer.buffer, offsets); - // Bind triangle index buffer - vkCmdBindIndexBuffer(commandBuffer, indexBuffer.buffer, 0, VK_INDEX_TYPE_UINT32); - // Draw indexed triangle - vkCmdDrawIndexed(commandBuffer, static_cast(indices), 1, 0, 0, 1); -} -void ext::vulkan::DeferredRenderingGraphic::initialize( const std::string& renderMode ) { - return initialize(this->device ? *device : ext::vulkan::device, ext::vulkan::getRenderMode(renderMode)); -} -void ext::vulkan::DeferredRenderingGraphic::initialize( Device& device, RenderMode& renderMode ) { - this->device = &device; - - std::vector vertices = { - { {-1.0f, 1.0f}, {0.0f, 0.0f}, }, - { {-1.0f, -1.0f}, {0.0f, 1.0f}, }, - { {1.0f, -1.0f}, {1.0f, 1.0f}, }, - { {1.0f, 1.0f}, {1.0f, 0.0f}, } - - /* - { {-1.0f, 1.0f}, {0.0f, 0.0f}, }, - { {-1.0f, -1.0f}, {0.0f, 1.0f}, }, - { {1.0f, -1.0f}, {1.0f, 1.0f}, }, - - { {-1.0f, 1.0f}, {0.0f, 0.0f}, }, - { {1.0f, -1.0f}, {1.0f, 1.0f}, }, - { {1.0f, 1.0f}, {1.0f, 0.0f}, } - */ - }; - - std::vector indices = { - 0, 1, 2, 0, 2, 3 - // 0, 1, 2, 3, 4, 5 - }; - - initializeBuffer( - (void*) vertices.data(), - vertices.size() * sizeof(Vertex), - VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, //VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, - false - ); - initializeBuffer( - (void*) indices.data(), - indices.size() * sizeof(uint32_t), - VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, //VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, - false - ); - this->indices = indices.size(); - // asset correct buffer sizes - assert( buffers.size() >= 2 ); - ext::vulkan::GraphicOld::initialize( device, renderMode ); - - // set descriptor layout - { - std::vector bindings = { - // Uniforms - ext::vulkan::initializers::descriptorSetLayoutBinding( - VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - VK_SHADER_STAGE_FRAGMENT_BIT, - 0 - ) - }; - auto& subpass = renderMode.renderTarget.passes[this->subpass]; - for ( auto& input : subpass.inputs ) { - bindings.push_back(ext::vulkan::initializers::descriptorSetLayoutBinding( - VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, - VK_SHADER_STAGE_FRAGMENT_BIT, - bindings.size() - )); - } - initializeDescriptorLayout(bindings, sizeof(pushConstants)); - } - - // Create uniform buffer - // max kludge - { - size_t MAX_LIGHTS = ext::vulkan::DeferredRenderingGraphic::maxLights; - struct UniformDescriptor { - struct Matrices { - alignas(16) pod::Matrix4f view[2]; - alignas(16) pod::Matrix4f projection[2]; - } matrices; - alignas(16) pod::Vector4f ambient; - struct Light { - alignas(16) pod::Vector4f position; - alignas(16) pod::Vector4f color; - } lights; - }; - size_t size = sizeof(UniformDescriptor) + sizeof(UniformDescriptor::Light) * (MAX_LIGHTS - 1); - uint8_t buffer[size]; for ( size_t i = 0; i < size; ++i ) buffer[i] = 0; - { - UniformDescriptor* uniforms = (UniformDescriptor*) &buffer[0]; - uniforms->ambient = { 1, 1, 1, 1 }; - UniformDescriptor::Light* lights = (UniformDescriptor::Light*) &buffer[sizeof(UniformDescriptor) - sizeof(UniformDescriptor::Light)]; - for ( size_t i = 0; i < MAX_LIGHTS; ++i ) { - UniformDescriptor::Light& light = lights[i]; - light.position = { 0, 0, 0, 0 }; - light.color = { 0, 0, 0, 0 }; - } - } - uniforms.create( size, (void*) &buffer ); - } - pod::Userdata& userdata = uniforms.data(); - initializeBuffer( - (void*) userdata.data, - userdata.len, - VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, - false - ); -/* - initializeBuffer( - (void*) &uniforms, - sizeof(uniforms), - VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, - false - ); -*/ - // Move uniform buffer to the front - { - for ( auto it = buffers.begin(); it != buffers.end(); ++it ) { - Buffer& buffer = *it; - if ( !(buffer.usageFlags & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) ) continue; - Buffer uniformBuffer = std::move(buffer); - buffers.erase(it); - buffers.insert( buffers.begin(), std::move(uniformBuffer) ); - break; - } - - } - // set pipeline - { - VkPipelineInputAssemblyStateCreateInfo inputAssemblyState = ext::vulkan::initializers::pipelineInputAssemblyStateCreateInfo( - VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, - 0, - VK_FALSE - ); - VkPipelineRasterizationStateCreateInfo rasterizationState = ext::vulkan::initializers::pipelineRasterizationStateCreateInfo( - VK_POLYGON_MODE_FILL, - VK_CULL_MODE_BACK_BIT, - // VK_CULL_MODE_NONE, - VK_FRONT_FACE_CLOCKWISE, - 0 - ); - std::vector blendAttachmentStates; - auto& subpass = renderMode.renderTarget.passes[this->subpass]; - for ( auto& input : subpass.colors ) { - VkPipelineColorBlendAttachmentState blendAttachmentState = ext::vulkan::initializers::pipelineColorBlendAttachmentState( - 0xf, - VK_FALSE - ); - blendAttachmentStates.push_back(blendAttachmentState); - } - VkPipelineColorBlendStateCreateInfo colorBlendState = ext::vulkan::initializers::pipelineColorBlendStateCreateInfo( - blendAttachmentStates.size(), - blendAttachmentStates.data() - ); - VkPipelineDepthStencilStateCreateInfo depthStencilState = ext::vulkan::initializers::pipelineDepthStencilStateCreateInfo( - VK_FALSE, - VK_FALSE, - //VK_COMPARE_OP_LESS_OR_EQUAL - VK_COMPARE_OP_GREATER_OR_EQUAL - ); - VkPipelineViewportStateCreateInfo viewportState = ext::vulkan::initializers::pipelineViewportStateCreateInfo( - 1, 1, 0 - ); - VkPipelineMultisampleStateCreateInfo multisampleState = ext::vulkan::initializers::pipelineMultisampleStateCreateInfo( - VK_SAMPLE_COUNT_1_BIT, - 0 - ); - std::vector dynamicStateEnables = { - VK_DYNAMIC_STATE_VIEWPORT, - VK_DYNAMIC_STATE_SCISSOR - }; - VkPipelineDynamicStateCreateInfo dynamicState = ext::vulkan::initializers::pipelineDynamicStateCreateInfo( - dynamicStateEnables.data(), - static_cast(dynamicStateEnables.size()), - 0 - ); - - // Binding description - std::vector vertexBindingDescriptions = { - ext::vulkan::initializers::vertexInputBindingDescription( - VERTEX_BUFFER_BIND_ID, - sizeof(Vertex), - VK_VERTEX_INPUT_RATE_VERTEX - ) - }; - // Attribute descriptions - // Describes memory layout and shader positions - std::vector vertexAttributeDescriptions = { - // Location 0 : Position - ext::vulkan::initializers::vertexInputAttributeDescription( - VERTEX_BUFFER_BIND_ID, - 0, - VK_FORMAT_R32G32_SFLOAT, - offsetof(Vertex, position) - ), - // Location 1 : Texture coordinates - ext::vulkan::initializers::vertexInputAttributeDescription( - VERTEX_BUFFER_BIND_ID, - 1, - VK_FORMAT_R32G32_SFLOAT, - offsetof(Vertex, uv) - ) - }; - - // Specialization Constants - - struct SpecializationConstants { - uint32_t lights; - } specializationConstants; - // grab requested light count - specializationConstants.lights = ext::vulkan::DeferredRenderingGraphic::maxLights; - - std::vector specializationMapEntries; - { - VkSpecializationMapEntry specializationMapEntry; - specializationMapEntry.constantID = 0; - specializationMapEntry.size = sizeof(specializationConstants.lights); - specializationMapEntry.offset = offsetof(SpecializationConstants, lights); - specializationMapEntries.push_back(specializationMapEntry); - } - VkSpecializationInfo specializationInfo{}; - specializationInfo.dataSize = sizeof(specializationConstants); - specializationInfo.mapEntryCount = static_cast(specializationMapEntries.size()); - specializationInfo.pMapEntries = specializationMapEntries.data(); - specializationInfo.pData = &specializationConstants; - // fragment shader - shader.stages[1].pSpecializationInfo = &specializationInfo; - - VkPipelineVertexInputStateCreateInfo vertexInputState = ext::vulkan::initializers::pipelineVertexInputStateCreateInfo(); - vertexInputState.vertexBindingDescriptionCount = static_cast(vertexBindingDescriptions.size()); - vertexInputState.pVertexBindingDescriptions = vertexBindingDescriptions.data(); - vertexInputState.vertexAttributeDescriptionCount = static_cast(vertexAttributeDescriptions.size()); - vertexInputState.pVertexAttributeDescriptions = vertexAttributeDescriptions.data(); - - VkGraphicsPipelineCreateInfo pipelineCreateInfo = ext::vulkan::initializers::pipelineCreateInfo( - pipelineLayout, - renderMode.renderTarget.renderPass, - 0 - ); - pipelineCreateInfo.pVertexInputState = &vertexInputState; - pipelineCreateInfo.pInputAssemblyState = &inputAssemblyState; - pipelineCreateInfo.pRasterizationState = &rasterizationState; - pipelineCreateInfo.pColorBlendState = &colorBlendState; - pipelineCreateInfo.pMultisampleState = &multisampleState; - pipelineCreateInfo.pViewportState = &viewportState; - pipelineCreateInfo.pDepthStencilState = &depthStencilState; - pipelineCreateInfo.pDynamicState = &dynamicState; - pipelineCreateInfo.stageCount = static_cast(shader.stages.size()); - pipelineCreateInfo.pStages = shader.stages.data(); - pipelineCreateInfo.subpass = this->subpass; - - initializePipeline(pipelineCreateInfo); - } - { - std::vector inputDescriptors; - auto& subpass = renderMode.renderTarget.passes[this->subpass]; - for ( auto& input : subpass.inputs ) { - inputDescriptors.push_back(ext::vulkan::initializers::descriptorImageInfo( - renderTarget->attachments[input.attachment].view, - input.layout - )); - } - // Set descriptor pool - initializeDescriptorPool({ - ext::vulkan::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1), - ext::vulkan::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, inputDescriptors.size()), - }, 1); - // Set descriptor set - std::vector writeDescriptorSets = { - // Binding 0 : Projection/View matrix uniform buffer - ext::vulkan::initializers::writeDescriptorSet( - descriptorSet, - VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - 0, - &(buffers.at(0).descriptor) - ) - }; - for ( size_t i = 0; i < inputDescriptors.size(); ++i ) { - writeDescriptorSets.push_back(ext::vulkan::initializers::writeDescriptorSet( - descriptorSet, - VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, - i + 1, - &inputDescriptors[i] - )); - } - initializeDescriptorSet(writeDescriptorSets); - } -} -void ext::vulkan::DeferredRenderingGraphic::destroy() { - ext::vulkan::GraphicOld::destroy(); -} \ No newline at end of file diff --git a/engine/src/ext/vulkan/graphics/rendertarget.cpp b/engine/src/ext/vulkan/graphics/rendertarget.cpp deleted file mode 100644 index 66d46980..00000000 --- a/engine/src/ext/vulkan/graphics/rendertarget.cpp +++ /dev/null @@ -1,453 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -namespace { - uint32_t VERTEX_BUFFER_BIND_ID = 0; -} -bool ext::vulkan::RenderTargetGraphic::autoAssignable() const { - return false; -} -std::string ext::vulkan::RenderTargetGraphic::name() const { - return "RenderTargetGraphic"; -} -void ext::vulkan::RenderTargetGraphic::createCommandBuffer( VkCommandBuffer commandBuffer ) { - assert( buffers.size() >= 2 ); - Buffer& vertexBuffer = buffers.at(1); - Buffer& indexBuffer = buffers.at(2); - - pushConstants = { ext::openvr::renderPass }; - vkCmdPushConstants( commandBuffer, pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(pushConstants), &pushConstants ); - // Bind descriptor sets describing shader binding points - vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, nullptr); - // Bind the rendering pipeline - // The pipeline (state object) contains all states of the rendering pipeline, binding it will set all the states specified at pipeline creation time - vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); - // Bind triangle vertex buffer (contains position and colors) - VkDeviceSize offsets[1] = { 0 }; - vkCmdBindVertexBuffers(commandBuffer, 0, 1, &vertexBuffer.buffer, offsets); - // Bind triangle index buffer - vkCmdBindIndexBuffer(commandBuffer, indexBuffer.buffer, 0, VK_INDEX_TYPE_UINT32); - // Draw indexed triangle - vkCmdDrawIndexed(commandBuffer, static_cast(indices), 1, 0, 0, 1); -} -void ext::vulkan::RenderTargetGraphic::initialize( const std::string& renderMode ) { - return initialize(this->device ? *device : ext::vulkan::device, ext::vulkan::getRenderMode(renderMode)); -} -void ext::vulkan::RenderTargetGraphic::initialize( Device& device, RenderMode& renderMode ) { - this->device = &device; - - std::vector vertices = { - - { {-1.0f, 1.0f}, {0.0f, 1.0f}, }, - { {-1.0f, -1.0f}, {0.0f, 0.0f}, }, - { {1.0f, -1.0f}, {1.0f, 0.0f}, }, - { {1.0f, 1.0f}, {1.0f, 1.0f}, } - - /* - { {-1.0f, 1.0f}, {0.0f, 0.0f}, }, - { {-1.0f, -1.0f}, {0.0f, 1.0f}, }, - { {1.0f, -1.0f}, {1.0f, 1.0f}, }, - - { {-1.0f, 1.0f}, {0.0f, 0.0f}, }, - { {1.0f, -1.0f}, {1.0f, 1.0f}, }, - { {1.0f, 1.0f}, {1.0f, 0.0f}, } - */ - }; - - std::vector indices = { - // 0, 1, 2, 0, 2, 3 - 0, 1, 2, 2, 3, 0 - // 2, 1, 0, 0, 3, 2 - // 0, 3, 2, 2, 1, 0 - // 0, 1, 2, 3, 4, 5 - }; - - initializeBuffer( - (void*) vertices.data(), - vertices.size() * sizeof(Vertex), - VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, //VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, - false - ); - initializeBuffer( - (void*) indices.data(), - indices.size() * sizeof(uint32_t), - VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, //VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, - false - ); - this->indices = indices.size(); - // asset correct buffer sizes - assert( buffers.size() >= 2 ); - ext::vulkan::GraphicOld::initialize( device, renderMode ); - // set descriptor layout - { - std::vector bindings = { - // Uniforms - ext::vulkan::initializers::descriptorSetLayoutBinding( - VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - VK_SHADER_STAGE_VERTEX_BIT, - 0 - ), - ext::vulkan::initializers::descriptorSetLayoutBinding( - VK_DESCRIPTOR_TYPE_SAMPLER, - VK_SHADER_STAGE_FRAGMENT_BIT, - 1 - ), - }; - /* - bindings.push_back(ext::vulkan::initializers::descriptorSetLayoutBinding( - VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, - VK_SHADER_STAGE_FRAGMENT_BIT, - bindings.size() - )); - */ - for ( auto& attachment : renderTarget->attachments ) { - if ( !(attachment.usage & VK_IMAGE_USAGE_SAMPLED_BIT) ) continue; - bindings.push_back(ext::vulkan::initializers::descriptorSetLayoutBinding( - VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, - VK_SHADER_STAGE_FRAGMENT_BIT, - bindings.size() - )); - //break; - } - /* - auto& subpass = renderMode.renderTarget.passes[this->subpass]; - for ( auto& color : subpass.colors ) { - bindings.push_back(ext::vulkan::initializers::descriptorSetLayoutBinding( - VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, - VK_SHADER_STAGE_FRAGMENT_BIT, - bindings.size() - )); - } - */ - initializeDescriptorLayout(bindings, sizeof(pushConstants)); - } -/* - initializeDescriptorLayout({ - // Vertex shader - ext::vulkan::initializers::descriptorSetLayoutBinding( - VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - VK_SHADER_STAGE_VERTEX_BIT, - 0 - ), - // Fragment shader - ext::vulkan::initializers::descriptorSetLayoutBinding( - VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, - VK_SHADER_STAGE_FRAGMENT_BIT, - 1 - ), - }, sizeof(pushConstants)); -*/ - // Create sampler - { - VkSamplerCreateInfo samplerInfo = {}; - samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; - samplerInfo.magFilter = VK_FILTER_NEAREST; - samplerInfo.minFilter = VK_FILTER_NEAREST; - samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; - samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; - samplerInfo.addressModeV = samplerInfo.addressModeU; - samplerInfo.addressModeW = samplerInfo.addressModeU; - samplerInfo.mipLodBias = 0.0f; - samplerInfo.maxAnisotropy = 1.0f; - samplerInfo.minLod = 0.0f; - samplerInfo.maxLod = 1.0f; - samplerInfo.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; - VK_CHECK_RESULT(vkCreateSampler(device, &samplerInfo, nullptr, &sampler)); - } - // Create uniform buffer - initializeBuffer( - (void*) &uniforms, - sizeof(uniforms), - VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, - false - ); - // Swap buffers - // Move uniform buffer to the front - { - for ( auto it = buffers.begin(); it != buffers.end(); ++it ) { - Buffer& buffer = *it; - if ( !(buffer.usageFlags & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) ) continue; - Buffer uniformBuffer = std::move(buffer); - buffers.erase(it); - buffers.insert( buffers.begin(), std::move(uniformBuffer) ); - break; - } - } -/* - buffers = { - std::move(buffers.at(2)), - std::move(buffers.at(0)), - std::move(buffers.at(1)), - }; -*/ - // set pipeline - { - VkPipelineInputAssemblyStateCreateInfo inputAssemblyState = ext::vulkan::initializers::pipelineInputAssemblyStateCreateInfo( - VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, - 0, - VK_FALSE - ); - VkPipelineRasterizationStateCreateInfo rasterizationState = ext::vulkan::initializers::pipelineRasterizationStateCreateInfo( - VK_POLYGON_MODE_FILL, - VK_CULL_MODE_BACK_BIT, - // VK_CULL_MODE_NONE, - ext::vulkan::GraphicOld::DEFAULT_WINDING_ORDER, - 0 - ); - - std::vector blendAttachmentStates; - for ( auto& attachment : renderMode.renderTarget.attachments ) { - if ( attachment.usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT ) { - VkPipelineColorBlendAttachmentState blendAttachmentState = ext::vulkan::initializers::pipelineColorBlendAttachmentState( - 0xf, - VK_FALSE - ); - blendAttachmentState.blendEnable = VK_TRUE; - blendAttachmentState.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; - blendAttachmentState.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; - blendAttachmentState.colorBlendOp = VK_BLEND_OP_ADD; - blendAttachmentState.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; - blendAttachmentState.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; - blendAttachmentState.alphaBlendOp = VK_BLEND_OP_ADD; - blendAttachmentStates.push_back(blendAttachmentState); - } - } - auto& subpass = renderMode.renderTarget.passes[this->subpass]; - VkPipelineColorBlendStateCreateInfo colorBlendState = ext::vulkan::initializers::pipelineColorBlendStateCreateInfo( - // renderMode.getType() == "Swapchain" ? 1 : blendAttachmentStates.size(), - subpass.colors.size(), - blendAttachmentStates.data() - ); - /* - VkPipelineColorBlendAttachmentState blendAttachmentState = ext::vulkan::initializers::pipelineColorBlendAttachmentState( - 0xf, - VK_FALSE - ); - VkPipelineColorBlendStateCreateInfo colorBlendState = ext::vulkan::initializers::pipelineColorBlendStateCreateInfo( - 1, - &blendAttachmentState - ); - */ - /* - VkPipelineColorBlendAttachmentState blendAttachmentState = ext::vulkan::initializers::pipelineColorBlendAttachmentState( - // VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT, - 0xf, - VK_FALSE - ); - blendAttachmentState.blendEnable = VK_TRUE; - blendAttachmentState.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; - blendAttachmentState.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; - blendAttachmentState.colorBlendOp = VK_BLEND_OP_ADD; - blendAttachmentState.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; - blendAttachmentState.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; - blendAttachmentState.alphaBlendOp = VK_BLEND_OP_ADD; - VkPipelineColorBlendStateCreateInfo colorBlendState = ext::vulkan::initializers::pipelineColorBlendStateCreateInfo( - 1, - &blendAttachmentState - ); - */ - /* - std::vector blendAttachmentStates; - for ( auto& attachment : renderMode.renderTarget.attachments ) { - if ( attachment.layout == VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT ) { - VkPipelineColorBlendAttachmentState blendAttachmentState = ext::vulkan::initializers::pipelineColorBlendAttachmentState( - 0xf, - VK_FALSE - ); - blendAttachmentStates.push_back(blendAttachmentState); - } - } - VkPipelineColorBlendStateCreateInfo colorBlendState = ext::vulkan::initializers::pipelineColorBlendStateCreateInfo( - blendAttachmentStates.size(), - blendAttachmentStates.data() - ); - colorBlendState.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; - colorBlendState.logicOpEnable = VK_FALSE; - colorBlendState.logicOp = VK_LOGIC_OP_COPY; - colorBlendState.blendConstants[0] = 0.0f; - colorBlendState.blendConstants[1] = 0.0f; - colorBlendState.blendConstants[2] = 0.0f; - colorBlendState.blendConstants[3] = 0.0f; - */ - VkPipelineDepthStencilStateCreateInfo depthStencilState = ext::vulkan::initializers::pipelineDepthStencilStateCreateInfo( - VK_TRUE, - VK_TRUE, - //VK_COMPARE_OP_LESS_OR_EQUAL - VK_COMPARE_OP_GREATER_OR_EQUAL - ); - VkPipelineViewportStateCreateInfo viewportState = ext::vulkan::initializers::pipelineViewportStateCreateInfo( - 1, 1, 0 - ); - VkPipelineMultisampleStateCreateInfo multisampleState = ext::vulkan::initializers::pipelineMultisampleStateCreateInfo( - VK_SAMPLE_COUNT_1_BIT, - 0 - ); - std::vector dynamicStateEnables = { - VK_DYNAMIC_STATE_VIEWPORT, - VK_DYNAMIC_STATE_SCISSOR - }; - VkPipelineDynamicStateCreateInfo dynamicState = ext::vulkan::initializers::pipelineDynamicStateCreateInfo( - dynamicStateEnables.data(), - static_cast(dynamicStateEnables.size()), - 0 - ); - - // Binding description - std::vector vertexBindingDescriptions = { - ext::vulkan::initializers::vertexInputBindingDescription( - VERTEX_BUFFER_BIND_ID, - sizeof(Vertex), - VK_VERTEX_INPUT_RATE_VERTEX - ) - }; - // Attribute descriptions - // Describes memory layout and shader positions - std::vector vertexAttributeDescriptions = { - // Location 0 : Position - ext::vulkan::initializers::vertexInputAttributeDescription( - VERTEX_BUFFER_BIND_ID, - 0, - VK_FORMAT_R32G32_SFLOAT, - offsetof(Vertex, position) - ), - // Location 1 : Texture coordinates - ext::vulkan::initializers::vertexInputAttributeDescription( - VERTEX_BUFFER_BIND_ID, - 1, - VK_FORMAT_R32G32_SFLOAT, - offsetof(Vertex, uv) - ) - }; - - VkPipelineVertexInputStateCreateInfo vertexInputState = ext::vulkan::initializers::pipelineVertexInputStateCreateInfo(); - vertexInputState.vertexBindingDescriptionCount = static_cast(vertexBindingDescriptions.size()); - vertexInputState.pVertexBindingDescriptions = vertexBindingDescriptions.data(); - vertexInputState.vertexAttributeDescriptionCount = static_cast(vertexAttributeDescriptions.size()); - vertexInputState.pVertexAttributeDescriptions = vertexAttributeDescriptions.data(); - - VkGraphicsPipelineCreateInfo pipelineCreateInfo = ext::vulkan::initializers::pipelineCreateInfo( - pipelineLayout, - renderMode.renderTarget.renderPass, - 0 - ); - pipelineCreateInfo.pVertexInputState = &vertexInputState; - pipelineCreateInfo.pInputAssemblyState = &inputAssemblyState; - pipelineCreateInfo.pRasterizationState = &rasterizationState; - pipelineCreateInfo.pColorBlendState = &colorBlendState; - pipelineCreateInfo.pMultisampleState = &multisampleState; - pipelineCreateInfo.pViewportState = &viewportState; - pipelineCreateInfo.pDepthStencilState = &depthStencilState; - pipelineCreateInfo.pDynamicState = &dynamicState; - pipelineCreateInfo.stageCount = static_cast(shader.stages.size()); - pipelineCreateInfo.pStages = shader.stages.data(); - pipelineCreateInfo.subpass = this->subpass; - - initializePipeline(pipelineCreateInfo); - } - - { - VkDescriptorImageInfo samplerDescriptor; samplerDescriptor.sampler = sampler; - std::vector colorDescriptors; - /* - colorDescriptors.push_back(ext::vulkan::initializers::descriptorImageInfo( - renderTarget->attachments[0].view, - VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL - )); - */ - // auto& subpass = renderMode.renderTarget.passes[this->subpass]; - for ( auto& attachment : renderTarget->attachments ) { - if ( !(attachment.usage & VK_IMAGE_USAGE_SAMPLED_BIT) ) continue; - colorDescriptors.push_back(ext::vulkan::initializers::descriptorImageInfo( - attachment.view, - VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL - )); - //break; - } - /* - auto& subpass = renderMode.renderTarget.passes[this->subpass]; - for ( auto& color : subpass.colors ) { - colorDescriptors.push_back(ext::vulkan::initializers::descriptorImageInfo( - renderTarget->attachments[color].view, - VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, - )); - } - */ - // Set descriptor pool - initializeDescriptorPool({ - ext::vulkan::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1), - ext::vulkan::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_SAMPLER, 1), - ext::vulkan::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, colorDescriptors.size()), - }, 1); - // Set descriptor set - std::vector writeDescriptorSets = { - // Binding 0 : Projection/View matrix uniform buffer - ext::vulkan::initializers::writeDescriptorSet( - descriptorSet, - VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - 0, - &(buffers.at(0).descriptor) - ), - // Binding 1 : Sampler - ext::vulkan::initializers::writeDescriptorSet( - descriptorSet, - VK_DESCRIPTOR_TYPE_SAMPLER, - 1, - &samplerDescriptor - ) - }; - for ( size_t i = 0; i < colorDescriptors.size(); ++i ) { - writeDescriptorSets.push_back(ext::vulkan::initializers::writeDescriptorSet( - descriptorSet, - VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, - i + 2, - &colorDescriptors[i] - )); - } - initializeDescriptorSet(writeDescriptorSets); - } -/* - // Set descriptor pool - initializeDescriptorPool({ - ext::vulkan::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1), - ext::vulkan::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1), - }, 2); - // Set descriptor set - { - VkDescriptorImageInfo renderTargetDescriptor = ext::vulkan::initializers::descriptorImageInfo( - renderTarget->attachments[0].view, - VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, - sampler - ); - - initializeDescriptorSet({ - // Binding 0 : Projection/View matrix uniform buffer - ext::vulkan::initializers::writeDescriptorSet( - descriptorSet, - VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - 0, - &(buffers.at(0).descriptor) - ), - // Binding 1 : Fragment shader texture sampler - // Fragment shader: layout (binding = 1) uniform sampler2D samplerColor; - ext::vulkan::initializers::writeDescriptorSet( - descriptorSet, - VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, - 1, - &renderTargetDescriptor - ) - }); - } -*/ -} -void ext::vulkan::RenderTargetGraphic::destroy() { - vkDestroySampler( *device, sampler, nullptr ); - ext::vulkan::GraphicOld::destroy(); -} \ No newline at end of file diff --git a/engine/src/ext/vulkan/rendermodes/deferred.cpp b/engine/src/ext/vulkan/rendermodes/deferred.cpp index 81ff6400..e5179868 100644 --- a/engine/src/ext/vulkan/rendermodes/deferred.cpp +++ b/engine/src/ext/vulkan/rendermodes/deferred.cpp @@ -53,7 +53,7 @@ void ext::vulkan::DeferredRenderMode::initialize( Device& device ) { renderTarget.addPass( VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, { attachments.output }, - { attachments.albedo, attachments.position, attachments.normals }, + { attachments.albedo, attachments.position, attachments.normals, attachments.depth }, attachments.depth ); } @@ -62,17 +62,6 @@ void ext::vulkan::DeferredRenderMode::initialize( Device& device ) { { uf::BaseMesh mesh; - /* - mesh.vertices = { - { {-1.0f, 1.0f}, {0.0f, 0.0f}, }, - { {-1.0f, -1.0f}, {0.0f, 1.0f}, }, - { {1.0f, -1.0f}, {1.0f, 1.0f}, }, - - { {-1.0f, 1.0f}, {0.0f, 0.0f}, }, - { {1.0f, -1.0f}, {1.0f, 1.0f}, }, - { {1.0f, 1.0f}, {1.0f, 0.0f}, } - }; - */ mesh.vertices = { { {-1.0f, 1.0f}, {0.0f, 0.0f}, }, { {-1.0f, -1.0f}, {0.0f, 1.0f}, }, @@ -94,17 +83,6 @@ void ext::vulkan::DeferredRenderMode::initialize( Device& device ) { }); blitter.initializePipeline(); } - // update layer rendertargets descriptor sets -/* - { - std::vector layers = ext::vulkan::getRenderModes("RenderTarget", false); //{ &ext::vulkan::getRenderMode("Gui") }; - for ( auto _ : layers ) { - RenderTargetRenderMode* layer = (RenderTargetRenderMode*) _; - auto& blitter = layer->blitter; - blitter.initialize( this->getName() ); - } - } -*/ } void ext::vulkan::DeferredRenderMode::tick() { ext::vulkan::RenderMode::tick(); @@ -113,21 +91,10 @@ void ext::vulkan::DeferredRenderMode::tick() { renderTarget.initialize( *renderTarget.device ); // update blitter descriptor set if ( blitter.initialized ) { - // blitter.material.textures.clear(); auto& pipeline = blitter.getPipeline(); pipeline.update( blitter ); } } -/* - std::vector layers = ext::vulkan::getRenderModes("RenderTarget", false); - for ( auto _ : layers ) { - RenderTargetRenderMode* layer = (RenderTargetRenderMode*) _; - auto& blitter = layer->blitter; - if ( blitter.initialized ) continue; - blitter.initialize( this->getName() ); - blitter.initializePipeline(); - } -*/ } void ext::vulkan::DeferredRenderMode::destroy() { ext::vulkan::RenderMode::destroy(); diff --git a/engine/src/ext/vulkan/rendermodes/rendertarget.cpp b/engine/src/ext/vulkan/rendermodes/rendertarget.cpp index 7e70780d..b55b9881 100644 --- a/engine/src/ext/vulkan/rendermodes/rendertarget.cpp +++ b/engine/src/ext/vulkan/rendermodes/rendertarget.cpp @@ -16,15 +16,6 @@ void ext::vulkan::RenderTargetRenderMode::initialize( Device& device ) { { renderTarget.device = &device; - // attach targets -/* - struct { - size_t color, depth; - } attachments; - - attachments.color = renderTarget.attach( VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL ); // albedo - attachments.depth = renderTarget.attach( device.formats.depth, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL ); // depth -*/ struct { size_t albedo, position, normals, depth, output; } attachments; @@ -58,8 +49,6 @@ void ext::vulkan::RenderTargetRenderMode::initialize( Device& device ) { { renderTarget.addPass( VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, - // { attachments.output }, - // { attachments.albedo, attachments.position, attachments.normals }, { attachments.output }, { attachments.albedo, attachments.position, attachments.normals }, attachments.depth @@ -79,22 +68,6 @@ void ext::vulkan::RenderTargetRenderMode::initialize( Device& device ) { mesh.indices = { 0, 1, 2, 2, 3, 0 }; - /* - mesh.vertices = { - { {-1.0f, 1.0f}, {0.0f, 0.0f}, }, - { {-1.0f, -1.0f}, {0.0f, 1.0f}, }, - { {1.0f, -1.0f}, {1.0f, 1.0f}, }, - - { {-1.0f, 1.0f}, {0.0f, 0.0f}, }, - { {1.0f, -1.0f}, {1.0f, 1.0f}, }, - { {1.0f, 1.0f}, {1.0f, 0.0f}, } - }; - */ - // blitter.descriptor.subpass = 1; - // blitter.descriptor.depthTest.test = false; - // blitter.descriptor.depthTest.write = false; - // blitter.initialize(this->getName()); - blitter.device = &device; blitter.material.device = &device; blitter.initializeGeometry( mesh ); diff --git a/engine/src/ext/vulkan/rendermodes/stereoscopic_deferred.cpp b/engine/src/ext/vulkan/rendermodes/stereoscopic_deferred.cpp index e0854f08..c4dc51d4 100644 --- a/engine/src/ext/vulkan/rendermodes/stereoscopic_deferred.cpp +++ b/engine/src/ext/vulkan/rendermodes/stereoscopic_deferred.cpp @@ -121,40 +121,7 @@ void ext::vulkan::StereoscopicDeferredRenderMode::initialize( Device& device ) { }); blitter.initializePipeline(); } - /* - blitter.renderTarget = &renderTarget; - blitter.initializeShaders({ - {"./data/shaders/display.subpass.vert.spv", VK_SHADER_STAGE_VERTEX_BIT}, - {"./data/shaders/display.subpass.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT} - }); - - blitter.subpass = 1; - blitter.initialize( device, *this ); - */ } -/* - { - blitter.renderTarget = &renderTarget; - blitter.initializeShaders({ - {"./data/shaders/display.vert.spv", VK_SHADER_STAGE_VERTEX_BIT}, - {"./data/shaders/display.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT} - }); - blitter.subpass = 2; - blitter.initialize( device, *this ); - } -*/ - // update layer rendertargets descriptor sets -/* - { - std::vector layers = ext::vulkan::getRenderModes("RenderTarget", false); //{ &ext::vulkan::getRenderMode("Gui") }; - for ( auto layer : layers ) { - RenderTargetRenderMode* rtLayer = (RenderTargetRenderMode*) layer; - auto& blitter = rtLayer->blitter; - // blitter.subpass = 1; - blitter.initialize( device, *this ); - } - } -*/ } void ext::vulkan::StereoscopicDeferredRenderMode::tick() { ext::vulkan::RenderMode::tick(); @@ -178,144 +145,6 @@ void ext::vulkan::StereoscopicDeferredRenderMode::tick() { } } } -/* - std::vector layers = ext::vulkan::getRenderModes("RenderTarget", false); - for ( auto layer : layers ) { - RenderTargetRenderMode* rtLayer = (RenderTargetRenderMode*) layer; - auto& blitter = rtLayer->blitter; - // update descriptor set - if ( !blitter.initialized ) { - // blitter.subpass = 1; - if ( blitter.renderTarget ) blitter.initialize( *device, *this ); - } - } - if ( ext::vulkan::resized ) { - struct EYES { - RenderTarget* renderTarget; - Graphic* blitter; - }; - std::vector eyes = { - { &renderTargets.left, &blitters.left }, - { &renderTargets.right, &blitters.right }, - }; - for ( auto& eye : eyes ) { - auto& renderTarget = *eye.renderTarget; - auto& blitter = *eye.blitter; - // destroy if exist - { - renderTarget.initialize( *renderTarget.device ); - } - // update blitter descriptor set - if ( blitter.initialized ) { - std::vector inputDescriptors; - auto& subpass = renderTarget.passes[blitter.subpass]; - for ( auto& input : subpass.inputs ) { - inputDescriptors.push_back(ext::vulkan::initializers::descriptorImageInfo( - renderTarget.attachments[input.attachment].view, - input.layout - )); - } - // Set descriptor set - std::vector writeDescriptorSets = { - // Binding 0 : Projection/View matrix uniform buffer - ext::vulkan::initializers::writeDescriptorSet( - blitter.descriptorSet, - VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - 0, - &(blitter.buffers.at(0).descriptor) - ) - }; - for ( size_t i = 0; i < inputDescriptors.size(); ++i ) { - writeDescriptorSets.push_back(ext::vulkan::initializers::writeDescriptorSet( - blitter.descriptorSet, - VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, - i + 1, - &inputDescriptors[i] - )); - } - blitter.initializeDescriptorSet( writeDescriptorSets ); - } - } - { - // update blitter descriptor set - if ( blitter.initialized ) { - std::vector inputDescriptors; - auto& subpass = renderTarget.passes[blitter.subpass]; - for ( auto& input : subpass.inputs ) { - inputDescriptors.push_back(ext::vulkan::initializers::descriptorImageInfo( - renderTarget.attachments[input.attachment].view, - input.layout - )); - } - // Set descriptor set - std::vector writeDescriptorSets = { - // Binding 0 : Projection/View matrix uniform buffer - ext::vulkan::initializers::writeDescriptorSet( - blitter.descriptorSet, - VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - 0, - &(blitter.buffers.at(0).descriptor) - ) - }; - for ( size_t i = 0; i < inputDescriptors.size(); ++i ) { - writeDescriptorSets.push_back(ext::vulkan::initializers::writeDescriptorSet( - blitter.descriptorSet, - VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, - i + 1, - &inputDescriptors[i] - )); - } - blitter.initializeDescriptorSet( writeDescriptorSets ); - } - } - // update layer rendertargets descriptor sets - for ( auto layer : layers ) { - RenderTargetRenderMode* rtLayer = (RenderTargetRenderMode*) layer; - auto& blitter = rtLayer->blitter; - auto& renderTarget = rtLayer->renderTarget; - // update descriptor set - if ( blitter.initialized ) { - VkDescriptorImageInfo samplerDescriptor; samplerDescriptor.sampler = blitter.sampler; - std::vector colorDescriptors; - - for ( auto& attachment : renderTarget.attachments ) { - colorDescriptors.push_back(ext::vulkan::initializers::descriptorImageInfo( - attachment.view, - VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL - )); - //break; - } - - // Set descriptor set - std::vector writeDescriptorSets = { - // Binding 0 : Projection/View matrix uniform buffer - ext::vulkan::initializers::writeDescriptorSet( - blitter.descriptorSet, - VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - 0, - &(blitter.buffers.at(0).descriptor) - ), - // Binding 1 : Sampler - ext::vulkan::initializers::writeDescriptorSet( - blitter.descriptorSet, - VK_DESCRIPTOR_TYPE_SAMPLER, - 1, - &samplerDescriptor - ), - }; - for ( size_t i = 0; i < colorDescriptors.size(); ++i ) { - writeDescriptorSets.push_back(ext::vulkan::initializers::writeDescriptorSet( - blitter.descriptorSet, - VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, - i + 2, - &colorDescriptors[i] - )); - } - vkUpdateDescriptorSets( *device, static_cast(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, nullptr ); - } - } - } -*/ } void ext::vulkan::StereoscopicDeferredRenderMode::destroy() { ext::vulkan::RenderMode::destroy(); diff --git a/engine/src/ext/vulkan/rendertarget.cpp b/engine/src/ext/vulkan/rendertarget.cpp index 4fedddf5..feee97d4 100644 --- a/engine/src/ext/vulkan/rendertarget.cpp +++ b/engine/src/ext/vulkan/rendertarget.cpp @@ -211,7 +211,7 @@ void ext::vulkan::RenderTarget::initialize( Device& device ) { VK_CHECK_RESULT(vkCreateRenderPass(device, &renderPassInfo, nullptr, &renderPass)); - std::cout << renderPass << ": " << attachments.size() << std::endl; + // std::cout << renderPass << ": " << attachments.size() << std::endl; } { diff --git a/engine/src/utils/string/ext.cpp b/engine/src/utils/string/ext.cpp index 511668ec..5cfeb539 100644 --- a/engine/src/utils/string/ext.cpp +++ b/engine/src/utils/string/ext.cpp @@ -46,14 +46,32 @@ std::string UF_API uf::string::uppercase( const std::string& str ) { } std::vector UF_API uf::string::split( const std::string& haystack, const std::string& needle ) { std::vector cont; + size_t last = 0, next = 0; + while ((next = haystack.find(needle, last)) != std::string::npos) { + cont.push_back(haystack.substr(last, next-last)); + last = next + 1; + } + cont.push_back( haystack.substr(last) ); +/* + std::string token; + size_t pos = 0; + while ((pos = haystack.find(needle)) != std::string::npos) { + cont.push_back( haystack.substr(0, pos) ); + haystack.erase(0, pos + needle.length()); + } + cont.push_back(haystack); +*/ + +/* std::size_t current, previous = 0; current = haystack.find_first_of(needle); while (current != std::string::npos) { cont.push_back(haystack.substr(previous, current - previous)); - previous = current + 1; + previous = current + needle.size(); current = haystack.find_first_of(needle, previous); } cont.push_back(haystack.substr(previous, current - previous)); +*/ return cont; } std::string UF_API uf::string::replace( const std::string& string, const std::string& search, const std::string& replace ) { diff --git a/ext/gui/gui.cpp b/ext/gui/gui.cpp index 099e35f7..bfb20045 100644 --- a/ext/gui/gui.cpp +++ b/ext/gui/gui.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include diff --git a/ext/main.cpp b/ext/main.cpp index 70352f32..680a220a 100644 --- a/ext/main.cpp +++ b/ext/main.cpp @@ -104,7 +104,7 @@ void EXT_API ext::initialize() { // Enable valiation layer ext::vulkan::validation = ::config["engine"]["ext"]["vulkan"]["validation"].asBool(); // - ext::vulkan::DeferredRenderingGraphic::maxLights = ::config["engine"]["scenes"]["max lights"].asUInt(); + // ext::vulkan::DeferredRenderingGraphic::maxLights = ::config["engine"]["scenes"]["max lights"].asUInt(); // ext::openvr::enabled = ::config["engine"]["ext"]["vr"]["enable"].asBool(); ext::openvr::swapEyes = ::config["engine"]["ext"]["vr"]["swap eyes"].asBool(); diff --git a/ext/scenes/world/gui/battle.cpp b/ext/scenes/world/gui/battle.cpp index 237a1cd8..5fdc7a28 100644 --- a/ext/scenes/world/gui/battle.cpp +++ b/ext/scenes/world/gui/battle.cpp @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include diff --git a/ext/scenes/world/gui/dialogue.cpp b/ext/scenes/world/gui/dialogue.cpp index 5e640db4..039d8272 100644 --- a/ext/scenes/world/gui/dialogue.cpp +++ b/ext/scenes/world/gui/dialogue.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include diff --git a/ext/scenes/world/gui/pause.cpp b/ext/scenes/world/gui/pause.cpp index fd07aa6f..772fc13f 100644 --- a/ext/scenes/world/gui/pause.cpp +++ b/ext/scenes/world/gui/pause.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include diff --git a/ext/scenes/world/housamo/battle.cpp b/ext/scenes/world/housamo/battle.cpp index c84f0f28..1d62859c 100644 --- a/ext/scenes/world/housamo/battle.cpp +++ b/ext/scenes/world/housamo/battle.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/ext/scenes/world/housamo/dialogue.cpp b/ext/scenes/world/housamo/dialogue.cpp index a273d12c..96a6c9fa 100644 --- a/ext/scenes/world/housamo/dialogue.cpp +++ b/ext/scenes/world/housamo/dialogue.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/ext/scenes/world/housamo/sprite.cpp b/ext/scenes/world/housamo/sprite.cpp index d5b846dc..727b0104 100644 --- a/ext/scenes/world/housamo/sprite.cpp +++ b/ext/scenes/world/housamo/sprite.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/ext/scenes/world/light/light.cpp b/ext/scenes/world/light/light.cpp new file mode 100644 index 00000000..f0abb2b8 --- /dev/null +++ b/ext/scenes/world/light/light.cpp @@ -0,0 +1,96 @@ +#include "light.h" + +#include +#include +#include +#include + +EXT_OBJECT_REGISTER_CPP(Light) +void ext::Light::initialize() { + uf::Object::initialize(); + auto& metadata = this->getComponent(); + auto& transform = this->getComponent>(); + auto& camera = this->getComponent(); + { + auto& scene = uf::scene::getCurrentScene(); + auto& controller = *scene.getController(); + camera = controller.getComponent(); + + camera.setFov( metadata["light"]["fov"].asFloat() ); + } + { + auto& renderMode = this->getComponent(); + renderMode.width = 512; + renderMode.height = 512; + std::string name = "Render Target: " + std::to_string((int) this->getUid()); + ext::vulkan::addRenderMode( &renderMode, name ); + } +} +void ext::Light::tick() { + uf::Object::tick(); + + auto& renderMode = this->getComponent(); + renderMode.target = ""; + + auto& camera = this->getComponent(); + auto& transform = this->getComponent>(); + for ( std::size_t i = 0; i < 2; ++i ) { + camera.setView( uf::matrix::inverse( uf::transform::model( transform ) ), i ); + } +} +void ext::Light::render() { + uf::Object::render(); +/* + { + auto& renderMode = this->getComponent(); + auto& blitter = renderMode.blitter; + + auto& transform = this->getComponent>(); + auto& scene = uf::scene::getCurrentScene(); + auto& controller = *scene.getController(); + auto& camera = this->getComponent(); + auto& controllerCamera = controller.getComponent(); + if ( !blitter.initialized ) return; + + struct UniformDescriptor { + struct { + alignas(16) pod::Matrix4f models[2]; + } matrices; + struct { + alignas(8) pod::Vector2f position = { 0.5f, 0.5f }; + alignas(8) pod::Vector2f radius = { 0.1f, 0.1f }; + alignas(16) pod::Vector4f color = { 1, 1, 1, 1 }; + } cursor; + alignas(4) float alpha; + }; + + auto& shader = blitter.material.shaders.front(); + auto& uniforms = shader.uniforms.front().get(); + + for ( std::size_t i = 0; i < 2; ++i ) { + pod::Matrix4f model = uf::transform::model( transform ); + + uniforms.matrices.models[i] = controllerCamera.getProjection(i) * controllerCamera.getView(i) * model; + + uniforms.alpha = 1.0f; + + uniforms.cursor.position.x = -1.0f; + uniforms.cursor.position.y = -1.0f; + + uniforms.cursor.radius.x = 0.0f; + uniforms.cursor.radius.y = 0.0f; + + uniforms.cursor.color.x = 0.0f; + uniforms.cursor.color.y = 0.0f; + uniforms.cursor.color.z = 0.0f; + uniforms.cursor.color.w = 0.0f; + } + shader.updateBuffer( (void*) &uniforms, sizeof(uniforms), 0 ); + } +*/ +} +void ext::Light::destroy() { + auto& renderMode = this->getComponent(); + ext::vulkan::removeRenderMode( &renderMode, false ); + uf::Object::destroy(); +} \ No newline at end of file diff --git a/ext/scenes/world/light/light.h b/ext/scenes/world/light/light.h new file mode 100644 index 00000000..e66fadd5 --- /dev/null +++ b/ext/scenes/world/light/light.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include +#include +#include + +namespace ext { + class EXT_API Light : public uf::Object { + public: + virtual void initialize(); + virtual void tick(); + virtual void render(); + virtual void destroy(); + }; +} \ No newline at end of file diff --git a/ext/scenes/world/portal/portal.cpp b/ext/scenes/world/portal/portal.cpp index bcd9e61c..b66ed005 100644 --- a/ext/scenes/world/portal/portal.cpp +++ b/ext/scenes/world/portal/portal.cpp @@ -69,7 +69,7 @@ void ext::Portal::initialize() { } { auto& renderMode = this->getComponent(); - std::string name = this->getName() + ": " + std::to_string((int) this->getUid()); + std::string name = "Render Target: " + std::to_string((int) this->getUid()); ext::vulkan::addRenderMode( &renderMode, name ); if ( ext::openvr::enabled ) { ext::openvr::initialize(); diff --git a/ext/scenes/world/terrain/generator.cpp b/ext/scenes/world/terrain/generator.cpp index 2ad0d752..0f247e23 100644 --- a/ext/scenes/world/terrain/generator.cpp +++ b/ext/scenes/world/terrain/generator.cpp @@ -1430,116 +1430,4 @@ void ext::TerrainGenerator::rasterize( std::vector& buffer, const ext::Region& region ) { - struct { - pod::Vector3f position; - struct { float u, v, x, y; } uv; - } offset; - - const ext::Terrain& terrain = region.getParent(); - const pod::Transform<>& transform = region.getComponent>(); - const pod::Vector3i location = { - transform.position.x / this->m_size.x, - transform.position.y / this->m_size.y, - transform.position.z / this->m_size.z, - }; - - struct { ext::Region* right = NULL; ext::Region* left = NULL; ext::Region* top = NULL; ext::Region* bottom = NULL; ext::Region* front = NULL; ext::Region* back = NULL; } regions; - - regions.right = terrain.at( { location.x + 1, location.y, location.z } ); - regions.left = terrain.at( { location.x - 1, location.y, location.z } ); - regions.top = terrain.at( { location.x, location.y + 1, location.z } ); - regions.bottom = terrain.at( { location.x, location.y - 1, location.z } ); - regions.front = terrain.at( { location.x, location.y, location.z + 1 } ); - regions.back = terrain.at( { location.x, location.y, location.z - 1 } ); -/* - for ( uint x = 0; x < this->m_size.x; ++x ) { - for ( uint y = 0; y < this->m_size.y; ++y ) { - for ( uint z = 0; z < this->m_size.z; ++z ) { - ext::TerrainVoxel voxel = ext::TerrainVoxel::atlas(this->m_voxels.id.raw[x][y][z]); -*/ - std::size_t i = 0; - for ( auto& _ : this->m_voxels.id.rle ) { - for ( std::size_t __ = 0; __ < _.length; ++__ ) { - { - std::size_t x = 0, y = 0, z = 0; - { - auto v = this->unwrapIndex( i++, this->m_voxels.id.swizzle ); - x = v.x; - y = v.y; - z = v.z; - } - - ext::TerrainVoxel voxel = ext::TerrainVoxel::atlas( _.value ); - offset.position.x = x - (this->m_size.x / 2.0f); - offset.position.y = y - (this->m_size.y / 2.0f); - offset.position.z = z - (this->m_size.z / 2.0f); - - const ext::TerrainVoxel::Model& model = voxel.model(); - if ( !voxel.opaque() ) continue; - - struct { - bool top = true, bottom = true, left = true, right = true, front = true, back = true; - } should; - struct { - ext::TerrainVoxel top = ext::TerrainVoxel::atlas(0), bottom = ext::TerrainVoxel::atlas(0), left = ext::TerrainVoxel::atlas(0), right = ext::TerrainVoxel::atlas(0), front = ext::TerrainVoxel::atlas(0), back = ext::TerrainVoxel::atlas(0); - } neighbor; - - if ( x > 0 ) neighbor.left = ext::TerrainVoxel::atlas(this->getVoxel(x-1,y,z)); else if ( regions.left != NULL ) { - const ext::Region& left = *regions.left; - const ext::TerrainGenerator& t = left.getComponent(); - neighbor.left = ext::TerrainVoxel::atlas(t.getVoxel(t.m_size.x-1,y,z)); - } - if ( y > 0 ) neighbor.bottom = ext::TerrainVoxel::atlas(this->getVoxel(x,y-1,z)); else if ( regions.bottom != NULL ) { - const ext::Region& bottom = *regions.bottom; - const ext::TerrainGenerator& t = bottom.getComponent(); - neighbor.bottom =ext::TerrainVoxel::atlas( t.getVoxel(x,t.m_size.y-1,z)); - } - if ( z > 0 ) neighbor.back = ext::TerrainVoxel::atlas(this->getVoxel(x,y,z-1)); else if ( regions.back != NULL ) { - const ext::Region& back = *regions.back; - const ext::TerrainGenerator& t = back.getComponent(); - neighbor.back = ext::TerrainVoxel::atlas(t.getVoxel(x,y,t.m_size.z-1)); - } - - if ( x + 1 < this->m_size.x ) neighbor.right = ext::TerrainVoxel::atlas(this->getVoxel(x+1,y,z)); else if ( regions.right != NULL ) { - const ext::Region& right = *regions.right; - const ext::TerrainGenerator& t = right.getComponent(); - neighbor.right = ext::TerrainVoxel::atlas(t.getVoxel(0,y,z)); - } - if ( y + 1 < this->m_size.y ) neighbor.top = ext::TerrainVoxel::atlas(this->getVoxel(x,y+1,z)); else if ( regions.top != NULL ) { - const ext::Region& top = *regions.top; - const ext::TerrainGenerator& t = top.getComponent(); - neighbor.top = ext::TerrainVoxel::atlas(t.getVoxel(x,0,z)); - } - if ( z + 1 < this->m_size.z ) neighbor.front = ext::TerrainVoxel::atlas(this->getVoxel(x,y,z+1)); else if ( regions.front != NULL ) { - const ext::Region& front = *regions.front; - const ext::TerrainGenerator& t = front.getComponent(); - neighbor.front = ext::TerrainVoxel::atlas(t.getVoxel(x,y,0)); - } - - should.right = !neighbor.right.opaque(); - should.left = !neighbor.left.opaque(); - should.top = !neighbor.top.opaque(); - should.bottom = !neighbor.bottom.opaque(); - should.front = !neighbor.front.opaque(); - should.back = !neighbor.back.opaque(); - - // occluded - if ( !should.right && !should.left && !should.top && !should.bottom && !should.front && !should.back ) continue; - if ( !voxel.opaque() ) continue; - - ext::vulkan::ComputeGraphic::Cube cube; - pod::Vector3f location = offset.position + transform.position; - cube.position.x = location.x; - cube.position.y = location.y; - cube.position.z = location.z; - cube.position.z *= -1; - cube.position.w = 0.5f; - cube.type = voxel.opaque() ? pod::Primitive::CUBE : pod::Primitive::EMPTY; - buffer.push_back(cube); - } - } - } } \ No newline at end of file diff --git a/ext/scenes/world/terrain/generator.h b/ext/scenes/world/terrain/generator.h index cc42cb78..56c39b89 100644 --- a/ext/scenes/world/terrain/generator.h +++ b/ext/scenes/world/terrain/generator.h @@ -12,7 +12,6 @@ #include #include -#include #include @@ -56,7 +55,8 @@ namespace ext { void generate( ext::Region& ); void rasterize( std::vector& vertices, const ext::Region& ); - void vectorize( std::vector&, const ext::Region& ); + // void vectorize( std::vector&, const ext::Region& ); + std::vector getRawVoxels(); const pod::RLE::string_t& getVoxels() const; diff --git a/ext/scenes/world/terrain/terrain.cpp b/ext/scenes/world/terrain/terrain.cpp index 8ffb444a..49615065 100644 --- a/ext/scenes/world/terrain/terrain.cpp +++ b/ext/scenes/world/terrain/terrain.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include diff --git a/ext/scenes/world/world.cpp b/ext/scenes/world/world.cpp index d37bed4e..4bfbf6df 100644 --- a/ext/scenes/world/world.cpp +++ b/ext/scenes/world/world.cpp @@ -424,10 +424,10 @@ uf::Entity* ext::World::getController() { auto& renderMode = *ext::vulkan::currentRenderMode; std::string name = renderMode.name; auto split = uf::string::split( name, ": " ); - if ( split.front() == "Portal" ) { + if ( split.front() == "Render Target" ) { uint64_t uid = std::stoi( split.back() ); - uf::Entity* portal = this->findByUid( uid ); - if ( portal ) return portal; + uf::Entity* ent = this->findByUid( uid ); + if ( ent ) return ent; } } return uf::Scene::getController();