diff --git a/engine/includes/components/component.h b/engine/includes/components/component.h index 082b5e88c..3de12588b 100644 --- a/engine/includes/components/component.h +++ b/engine/includes/components/component.h @@ -36,6 +36,8 @@ class ENGINE_EXPORT Component : public Object { bool isEnabled() const; virtual void setEnabled(bool enable); + bool isEnabledInHierarchy() const; + bool isStarted() const; void setStarted(bool started); diff --git a/engine/includes/editor/viewport/tasks/gizmorender.h b/engine/includes/editor/viewport/tasks/gizmorender.h index f66b9bfde..c2c4b9e61 100644 --- a/engine/includes/editor/viewport/tasks/gizmorender.h +++ b/engine/includes/editor/viewport/tasks/gizmorender.h @@ -122,7 +122,6 @@ class GizmoRender : public PipelineTask { t->setQuaternion(q); t->setPosition(q * Vector3(0.0f, 0.0f, gNaviCubeDist)); - buffer->clearRenderTarget(false); buffer->setViewport(m_width-gNaviCubeSize, m_height-gNaviCubeSize, gNaviCubeSize, gNaviCubeSize); buffer->setViewProjection(m_camera->viewMatrix(), m_camera->projectionMatrix()); buffer->drawMesh(PipelineContext::defaultCube(), 0, CommandBuffer::UI, *m_cubeMaterial); diff --git a/engine/includes/editor/viewport/tasks/outlinerender.h b/engine/includes/editor/viewport/tasks/outlinerender.h index 1edd215c7..a88039e70 100644 --- a/engine/includes/editor/viewport/tasks/outlinerender.h +++ b/engine/includes/editor/viewport/tasks/outlinerender.h @@ -37,6 +37,7 @@ class Outline : public PipelineTask { m_outlineTarget->setColorAttachment(0, m_outlineMap); m_outlineTarget->setDepthAttachment(m_outlineDepth); + m_outlineTarget->setClearFlags(RenderTarget::ClearColor | RenderTarget::ClearDepth); Material *material = Engine::loadResource(".embedded/outline.shader"); if(material) { @@ -83,7 +84,6 @@ class Outline : public PipelineTask { buffer->beginDebugMarker("Outline"); buffer->setRenderTarget(m_outlineTarget); - buffer->clearRenderTarget(); RenderList filter; for(auto actor : m_controller->selected()) { for(auto it : m_context->culledComponents()) { diff --git a/engine/includes/pipelinecontext.h b/engine/includes/pipelinecontext.h index 37a1ae55f..ac78d4d5d 100644 --- a/engine/includes/pipelinecontext.h +++ b/engine/includes/pipelinecontext.h @@ -65,7 +65,7 @@ class ENGINE_EXPORT PipelineContext : public Object { std::list > &culledPostEffectSettings(); - void frustumCulling(const Frustum &frustum, const RenderList &in, RenderList &out, AABBox &box); + void frustumCulling(const Frustum &frustum, const RenderList &in, RenderList &out, AABBox *box = nullptr); void setPipeline(Pipeline *pipeline); void insertRenderTask(PipelineTask *task, PipelineTask *before = nullptr); @@ -131,6 +131,8 @@ class ENGINE_EXPORT PipelineContext : public Object { bool m_frustumCulling; + bool m_renderablesSorting; + }; #endif // PIPELINECONTEXT diff --git a/engine/includes/resources/rendertarget.h b/engine/includes/resources/rendertarget.h index b4dc5ee84..cc0c63407 100644 --- a/engine/includes/resources/rendertarget.h +++ b/engine/includes/resources/rendertarget.h @@ -10,6 +10,13 @@ class ENGINE_EXPORT RenderTarget : public Resource { A_NOPROPERTIES() A_NOMETHODS() + + enum ClearFlags { + DoNothing = 0, + ClearColor, + ClearDepth + }; + A_NOENUMS() public: @@ -24,6 +31,12 @@ class ENGINE_EXPORT RenderTarget : public Resource { Texture *depthAttachment() const; virtual void setDepthAttachment(Texture *texture); + int clearFlags() const; + void setClearFlags(int flags); + + void clearRegion(int32_t &x, int32_t &y, int32_t &width, int32_t &height) const; + void setClearRegion(int32_t x, int32_t y, int32_t width, int32_t height); + protected: void makeNative(); bool isNative() const; @@ -36,7 +49,17 @@ class ENGINE_EXPORT RenderTarget : public Resource { Texture *m_depth; - bool m_native = false; + int m_clearFlags; + + int m_clearX; + + int m_clearY; + + int m_clearWidth; + + int m_clearHeigh; + + bool m_native; }; diff --git a/engine/src/components/component.cpp b/engine/src/components/component.cpp index 4d3e6e96d..f16e4df3e 100644 --- a/engine/src/components/component.cpp +++ b/engine/src/components/component.cpp @@ -64,6 +64,16 @@ bool Component::isEnabled() const { void Component::setEnabled(bool enabled) { m_enable = enabled; } +/*! + Returns false in case of one of Actors in top hierarchy or this component was disabled; otherwise returns true. +*/ +bool Component::isEnabledInHierarchy() const { + Actor *actor = Component::actor(); + if(actor) { + return actor->isEnabledInHierarchy() && m_enable; + } + return m_enable; +} /*! Returns true if the component is flagged as started; otherwise returns false. \note This method is used for internal purposes and shouldn't be called manually. diff --git a/engine/src/pipelinecontext.cpp b/engine/src/pipelinecontext.cpp index 036563622..f8ca6c8e8 100644 --- a/engine/src/pipelinecontext.cpp +++ b/engine/src/pipelinecontext.cpp @@ -50,7 +50,8 @@ PipelineContext::PipelineContext() : m_camera(nullptr), m_width(64), m_height(64), - m_frustumCulling(true) { + m_frustumCulling(true), + m_renderablesSorting(true) { Material *mtl = Engine::loadResource(".embedded/DefaultPostEffect.shader"); if(mtl) { @@ -65,6 +66,11 @@ PipelineContext::PipelineContext() : PipelineContext::~PipelineContext() { m_textureBuffers.clear(); + + m_defaultTarget->deleteLater(); + m_buffer->deleteLater(); + + delete m_finalMaterial; } /*! Retrieves the command buffer associated with the pipeline context. @@ -83,10 +89,8 @@ void PipelineContext::draw(Camera *camera) { setCurrentCamera(camera); for(auto it : m_renderTasks) { - if(it) { - if(it->isEnabled()) { - it->exec(); - } + if(it && it->isEnabled()) { + it->exec(); } } @@ -94,7 +98,6 @@ void PipelineContext::draw(Camera *camera) { // Finish m_buffer->setRenderTarget(m_defaultTarget); - m_buffer->clearRenderTarget(); m_buffer->drawMesh(defaultPlane(), 0, CommandBuffer::UI, *m_finalMaterial); for(auto it : m_postObservers) { @@ -201,58 +204,50 @@ void PipelineContext::analizeGraph() { // Add renderables m_sceneComponents.clear(); for(auto it : RenderSystem::renderables()) { - if(it->isEnabled()) { - Actor *actor = it->actor(); - if(actor && (actor->world() == m_world) && actor->isEnabledInHierarchy()) { - if(update) { - it->update(); - } - m_sceneComponents.push_back(it); + if(it->world() == m_world && it->isEnabledInHierarchy()) { + if(update) { + it->update(); } + m_sceneComponents.push_back(it); } } - // Renderables cull and sort + // Renderables frustum culling if(m_frustumCulling) { - frustumCulling(camera->frustum(), m_sceneComponents, m_culledComponents, m_worldBound); + frustumCulling(camera->frustum(), m_sceneComponents, m_culledComponents, &m_worldBound); } - Vector3 origin = cameraTransform->position(); - culledComponents().sort([origin](const Renderable *left, const Renderable *right) { - int p1 = left->priority(); - int p2 = right->priority(); - if(p1 == p2) { - const Matrix4 &m1 = left->transform()->worldTransform(); - const Matrix4 &m2 = right->transform()->worldTransform(); - - return origin.dot(Vector3(m1[12], m1[13], m1[14])) < origin.dot(Vector3(m2[12], m2[13], m2[14])); - } - return p1 < p2; - }); + // Renderables sort + if(m_renderablesSorting) { + Vector3 origin(cameraTransform->worldPosition()); + culledComponents().sort([origin](const Renderable *left, const Renderable *right) { + int p1 = left->priority(); + int p2 = right->priority(); + if(p1 == p2) { + const Matrix4 &m1 = left->transform()->worldTransform(); + const Matrix4 &m2 = right->transform()->worldTransform(); + + return origin.dot(Vector3(m1[12], m1[13], m1[14])) < origin.dot(Vector3(m2[12], m2[13], m2[14])); + } + return p1 < p2; + }); + } // Add lights m_sceneLights.clear(); for(auto it : RenderSystem::lights()) { - if(it->isEnabled()) { - Actor *actor = it->actor(); - if(actor && actor->isEnabledInHierarchy()) { - if((actor->world() == m_world)) { - m_sceneLights.push_back(it); - } - } + if(it->world() == m_world && it->isEnabledInHierarchy()) { + m_sceneLights.push_back(it); } } // Add Post process volumes m_culledPostProcessSettings.clear(); for(auto it : RenderSystem::postProcessVolumes()) { - if(it->isEnabled()) { - Actor *actor = it->actor(); - if(actor && (actor->world() == m_world) && actor->isEnabledInHierarchy()) { - if(!it->unbound() && !it->bound().intersect(cameraTransform->worldPosition(), camera->nearPlane())) { - continue; - } - m_culledPostProcessSettings.push_back(std::make_pair(it->settings(), it->blendWeight())); + if(it->world() == m_world && it->isEnabledInHierarchy()) { + if(!it->unbound() && !it->bound().intersect(cameraTransform->worldPosition(), camera->nearPlane())) { + continue; } + m_culledPostProcessSettings.push_back(std::make_pair(it->settings(), it->blendWeight())); } } @@ -469,15 +464,19 @@ Camera *PipelineContext::currentCamera() const { Filters out an incoming \a list which are not in the \a frustum. Returns filtered list. The output parameter returns a bounding \a box for filtered objects. */ -void PipelineContext::frustumCulling(const Frustum &frustum, const RenderList &in, RenderList &out, AABBox &box) { - box.extent = Vector3(-1.0f); +void PipelineContext::frustumCulling(const Frustum &frustum, const RenderList &in, RenderList &out, AABBox *box) { + if(box) { + box->extent = Vector3(-1.0f); + } out.clear(); for(auto it : in) { AABBox bb = it->bound(); if(bb.extent.x < 0.0f || frustum.contains(bb)) { out.push_back(it); - box.encapsulate(bb); + if(box) { + box->encapsulate(bb); + } } } } diff --git a/engine/src/pipelinetasks/bloom.cpp b/engine/src/pipelinetasks/bloom.cpp index 2578dfd55..d3085adb5 100644 --- a/engine/src/pipelinetasks/bloom.cpp +++ b/engine/src/pipelinetasks/bloom.cpp @@ -47,6 +47,7 @@ Bloom::Bloom() : m_blurTempTexture->setFlags(Texture::Render); m_blurTempTarget->setColorAttachment(0, m_blurTempTexture); + m_blurTempTarget->setClearFlags(RenderTarget::ClearColor); if(blur) { for(uint8_t i = 0; i < BLOOM_PASSES; i++) { @@ -117,7 +118,6 @@ void Bloom::exec() { for(uint8_t i = 0; i < BLOOM_PASSES; i++) { buffer->setRenderTarget(m_blurTempTarget); - buffer->clearRenderTarget(true, Vector4(0.0f), false, 1.0f); buffer->drawMesh(PipelineContext::defaultPlane(), 0, CommandBuffer::UI, *m_bloomPasses[i].blurMaterialH); buffer->setRenderTarget(m_resultTarget); diff --git a/engine/src/pipelinetasks/gbuffer.cpp b/engine/src/pipelinetasks/gbuffer.cpp index 263a68cd4..03b3f8b2f 100644 --- a/engine/src/pipelinetasks/gbuffer.cpp +++ b/engine/src/pipelinetasks/gbuffer.cpp @@ -52,6 +52,8 @@ GBuffer::GBuffer() : m_gbuffer->setColorAttachment(i, m_outputs[i].second); } } + + m_gbuffer->setClearFlags(RenderTarget::ClearColor | RenderTarget::ClearDepth); } void GBuffer::exec() { @@ -62,7 +64,6 @@ void GBuffer::exec() { m_context->cameraReset(); buffer->setRenderTarget(m_gbuffer); - buffer->clearRenderTarget(); m_context->drawRenderers(m_context->culledComponents(), CommandBuffer::DEFAULT); diff --git a/engine/src/pipelinetasks/shadowmap.cpp b/engine/src/pipelinetasks/shadowmap.cpp index c505a8ca3..4fd6c28ed 100644 --- a/engine/src/pipelinetasks/shadowmap.cpp +++ b/engine/src/pipelinetasks/shadowmap.cpp @@ -116,6 +116,7 @@ void ShadowMap::areaLightUpdate(AreaLight *light, std::list &compo uint32_t pageSize = Texture::maxTextureSize(); buffer->setRenderTarget(shadowTarget); + for(int32_t i = 0; i < m_directions.size(); i++) { Matrix4 mat((wp * Matrix4(m_directions[i].toMatrix())).inverse()); matrix[i] = m_scale * crop * mat; @@ -125,18 +126,13 @@ void ShadowMap::areaLightUpdate(AreaLight *light, std::list &compo static_cast(w[i]) / pageSize, static_cast(h[i]) / pageSize); - buffer->enableScissor(x[i], y[i], w[i], h[i]); - buffer->clearRenderTarget(); - buffer->disableScissor(); - buffer->setViewProjection(mat, crop); buffer->setViewport(x[i], y[i], w[i], h[i]); - AABBox bb; auto frustum = Camera::frustum(false, 90.0f, 1.0f, position, m_directions[i], zNear, zFar); // Draw in the depth buffer from position of the light source RenderList culled; - m_context->frustumCulling(frustum, components, culled, bb); + m_context->frustumCulling(frustum, components, culled); m_context->drawRenderers(culled, CommandBuffer::SHADOWCAST); } @@ -195,8 +191,6 @@ void ShadowMap::directLightUpdate(DirectLight *light, std::list &c Matrix4 matrix[MAX_LODS]; buffer->setRenderTarget(shadowTarget); - buffer->enableScissor(x[0], y[0], x[MAX_LODS-1] + w[MAX_LODS-1], y[MAX_LODS-1] + h[MAX_LODS-1]); - buffer->clearRenderTarget(); for(int32_t lod = 0; lod < MAX_LODS; lod++) { float dist = distance[lod]; @@ -209,9 +203,8 @@ void ShadowMap::directLightUpdate(DirectLight *light, std::list &c box *= lightRot; AABBox bb; - auto frustum = Camera::frustum(true, box.extent.y * 2.0f, 1.0f, box.center, lightRot, -FLT_MAX, FLT_MAX); RenderList culled; - m_context->frustumCulling(frustum, components, culled, bb); + m_context->frustumCulling(Camera::frustum(true, box.extent.y * 2.0f, 1.0f, box.center, lightRot, -FLT_MAX, FLT_MAX), components, culled, &bb); float radius = MAX(box.radius, bb.radius); @@ -235,8 +228,6 @@ void ShadowMap::directLightUpdate(DirectLight *light, std::list &c // Draw in the depth buffer from position of the light source m_context->drawRenderers(culled, CommandBuffer::SHADOWCAST); - - buffer->disableScissor(); } auto instance = light->material(); @@ -279,6 +270,7 @@ void ShadowMap::pointLightUpdate(PointLight *light, std::list &com uint32_t pageSize = Texture::maxTextureSize(); buffer->setRenderTarget(shadowTarget); + for(int32_t i = 0; i < m_directions.size(); i++) { Matrix4 mat((wp * Matrix4(m_directions[i].toMatrix())).inverse()); matrix[i] = m_scale * crop * mat; @@ -288,19 +280,13 @@ void ShadowMap::pointLightUpdate(PointLight *light, std::list &com static_cast(w[i]) / pageSize, static_cast(h[i]) / pageSize); - buffer->enableScissor(x[i], y[i], w[i], h[i]); - buffer->clearRenderTarget(); - buffer->disableScissor(); - buffer->setViewProjection(mat, crop); buffer->setViewport(x[i], y[i], w[i], h[i]); - AABBox bb; - auto frustum = Camera::frustum(false, 90.0f, 1.0f, position, m_directions[i], zNear, zFar); + RenderList culled; + m_context->frustumCulling(Camera::frustum(false, 90.0f, 1.0f, position, m_directions[i], zNear, zFar), components, culled); // Draw in the depth buffer from position of the light source - RenderList culled; - m_context->frustumCulling(frustum, components, culled, bb); m_context->drawRenderers(culled, CommandBuffer::SHADOWCAST); } @@ -336,19 +322,14 @@ void ShadowMap::spotLightUpdate(SpotLight *light, std::list &compo RenderTarget *shadowTarget = requestShadowTiles(light->uuid(), 1, &x, &y, &w, &h, 1); buffer->setRenderTarget(shadowTarget); - buffer->enableScissor(x, y, w, h); - buffer->clearRenderTarget(); - buffer->disableScissor(); buffer->setViewProjection(rot, crop); buffer->setViewport(x, y, w, h); - AABBox bb; - auto frustum = Camera::frustum(false, light->outerAngle() * 2.0f, 1.0f, position, q, zNear, zFar); + RenderList culled; + m_context->frustumCulling(Camera::frustum(false, light->outerAngle() * 2.0f, 1.0f, position, q, zNear, zFar), components, culled); // Draw in the depth buffer from position of the light source - RenderList culled; - m_context->frustumCulling(frustum, components, culled, bb); m_context->drawRenderers(culled, CommandBuffer::SHADOWCAST); auto instance = light->material(); @@ -445,6 +426,7 @@ RenderTarget *ShadowMap::requestShadowTiles(uint32_t id, uint32_t lod, int32_t * target = Engine::objectCreate(); target->setDepthAttachment(map); + target->setClearFlags(RenderTarget::ClearDepth); AtlasNode *root = new AtlasNode; @@ -471,5 +453,9 @@ RenderTarget *ShadowMap::requestShadowTiles(uint32_t id, uint32_t lod, int32_t * if(tiles.size() == count) { m_tiles[id] = make_pair(target, tiles); } + + + + target->setClearRegion(x[0], y[0], width * columns, height * rows); return target; } diff --git a/engine/src/resources/rendertarget.cpp b/engine/src/resources/rendertarget.cpp index 9be2da9e2..50bdc06a4 100644 --- a/engine/src/resources/rendertarget.cpp +++ b/engine/src/resources/rendertarget.cpp @@ -8,6 +8,11 @@ RenderTarget::RenderTarget() : m_depth(nullptr), + m_clearFlags(DoNothing), + m_clearX(0), + m_clearY(0), + m_clearWidth(0), + m_clearHeigh(0), m_native(false) { } @@ -58,6 +63,36 @@ Texture *RenderTarget::depthAttachment() const { void RenderTarget::setDepthAttachment(Texture *texture) { m_depth = texture; } +/*! + Returns clear buffers startegy used on render target bind. +*/ +int RenderTarget::clearFlags() const { + return m_clearFlags; +} +/*! + Sets clear buffers startegy on bind using clear \a flags. +*/ +void RenderTarget::setClearFlags(int flags) { + m_clearFlags = flags; +} +/*! + Returns the region to be cleared. +*/ +void RenderTarget::clearRegion(int32_t &x, int32_t &y, int32_t &width, int32_t &height) const { + x = m_clearX; + y = m_clearY; + width = m_clearWidth; + height = m_clearHeigh; +} +/*! + Sets clear region at \a x \a y position and \a width \a height dimensions. +*/ +void RenderTarget::setClearRegion(int32_t x, int32_t y, int32_t width, int32_t height) { + m_clearX = x; + m_clearY = y; + m_clearWidth = width; + m_clearHeigh = height; +} /*! \internal */ diff --git a/modules/editor/shadertools/converter/shadergraph.cpp b/modules/editor/shadertools/converter/shadergraph.cpp index 919624d77..8c41b1d19 100644 --- a/modules/editor/shadertools/converter/shadergraph.cpp +++ b/modules/editor/shadertools/converter/shadergraph.cpp @@ -846,7 +846,6 @@ void ShaderGraph::updatePreviews(CommandBuffer &buffer) { } } buffer.setRenderTarget(it.second.target); - buffer.clearRenderTarget(true, Vector4(0, 0, 0, 1)); buffer.drawMesh(PipelineContext::defaultPlane(), 0, CommandBuffer::TRANSLUCENT, *it.second.instance); } } @@ -882,6 +881,7 @@ Texture *ShaderGraph::preview(GraphNode *node) { data.target = Engine::objectCreate((name + "_rt").toStdString()); data.target->setColorAttachment(0, data.texture); + data.target->setClearFlags(RenderTarget::ClearColor); data.material = Engine::objectCreate(); diff --git a/modules/renders/rendergl/src/commandbuffergl.cpp b/modules/renders/rendergl/src/commandbuffergl.cpp index 423b7bb9c..e529684e6 100644 --- a/modules/renders/rendergl/src/commandbuffergl.cpp +++ b/modules/renders/rendergl/src/commandbuffergl.cpp @@ -92,6 +92,24 @@ void CommandBufferGL::setRenderTarget(RenderTarget *target, uint32_t level) { RenderTargetGL *t = static_cast(target); if(t) { t->bindBuffer(level); + + int32_t x, y, w, h; + t->clearRegion(x, y, w, h); + + bool region = false; + if(w > 0 || h > 0) { + enableScissor(x, y, w, h); + region = true; + } + + int flags = t->clearFlags(); + if(flags) { + clearRenderTarget(flags & RenderTarget::ClearColor, Vector4(), flags & RenderTarget::ClearDepth); + } + + if(region) { + disableScissor(); + } } } diff --git a/modules/renders/rendervk/src/resources/rendertargetvk.cpp b/modules/renders/rendervk/src/resources/rendertargetvk.cpp index 799ef818f..fe908dd8c 100644 --- a/modules/renders/rendervk/src/resources/rendertargetvk.cpp +++ b/modules/renders/rendervk/src/resources/rendertargetvk.cpp @@ -101,22 +101,33 @@ void RenderTargetVk::bindBuffer(VkCommandBuffer &buffer) { std::vector clearValues; clearValues.reserve(count + 1); - for(uint32_t i = 0; i < count; i++) { - VkClearValue value; - value.color = { { 0.0f, 0.0f, 0.0f, 0.0f } }; + int32_t flags = clearFlags(); + if(flags & RenderTarget::ClearColor) { + for(uint32_t i = 0; i < count; i++) { + VkClearValue value; + value.color = { { 0.0f, 0.0f, 0.0f, 0.0f } }; + + clearValues.push_back(value); + } + } + if(flags & RenderTarget::ClearDepth) { + VkClearValue value; + value.depthStencil = { 1.0f, 0 }; clearValues.push_back(value); } - VkClearValue value; - value.depthStencil = { 1.0f, 0 }; - clearValues.push_back(value); + + int32_t x, y, w, h; + clearRegion(x, y, w, h); VkRenderPassBeginInfo renderPassBeginInfo = {}; renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; renderPassBeginInfo.renderPass = m_renderPass; renderPassBeginInfo.framebuffer = m_frameBuffer; - renderPassBeginInfo.renderArea.extent.width = m_width; - renderPassBeginInfo.renderArea.extent.height = m_height; + renderPassBeginInfo.renderArea.offset.x = x; + renderPassBeginInfo.renderArea.offset.y = y; + renderPassBeginInfo.renderArea.extent.width = (w == 0) ? m_width : w; + renderPassBeginInfo.renderArea.extent.height = (h == 0) ? m_height : h; renderPassBeginInfo.clearValueCount = clearValues.size(); renderPassBeginInfo.pClearValues = clearValues.data(); @@ -138,7 +149,7 @@ bool RenderTargetVk::updateBuffer(uint32_t level) { } if(m_frameBuffer == nullptr) { - //bool clearOnBind = false; + bool clearOnBind = (clearFlags() != 0); VkDevice device = WrapperVk::device(); @@ -152,7 +163,7 @@ bool RenderTargetVk::updateBuffer(uint32_t level) { VkAttachmentDescription description; description.samples = VK_SAMPLE_COUNT_1_BIT; - description.loadOp = /*clearOnBind ? VK_ATTACHMENT_LOAD_OP_CLEAR :*/ VK_ATTACHMENT_LOAD_OP_LOAD; + description.loadOp = clearOnBind ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD; description.storeOp = VK_ATTACHMENT_STORE_OP_STORE; description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; description.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; @@ -168,7 +179,7 @@ bool RenderTargetVk::updateBuffer(uint32_t level) { attachments.push_back(imageInfo.imageView); description.format = t->vkFormat(); - description.initialLayout = /*clearOnBind ? VK_IMAGE_LAYOUT_UNDEFINED :*/ t->initialLayout(); + description.initialLayout = clearOnBind ? VK_IMAGE_LAYOUT_UNDEFINED : t->initialLayout(); description.finalLayout = t->finalLayout(); } @@ -192,9 +203,9 @@ bool RenderTargetVk::updateBuffer(uint32_t level) { attachments.push_back(imageInfo.imageView); description.format = d->vkFormat(); - description.loadOp = /*clearOnBind ? VK_ATTACHMENT_LOAD_OP_CLEAR :*/ VK_ATTACHMENT_LOAD_OP_LOAD; - description.stencilLoadOp = /*clearOnBind ? VK_ATTACHMENT_LOAD_OP_CLEAR :*/ VK_ATTACHMENT_LOAD_OP_LOAD; - description.initialLayout = /*clearOnBind ? VK_IMAGE_LAYOUT_UNDEFINED :*/ d->initialLayout(); + description.loadOp = clearOnBind ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD; + description.stencilLoadOp = clearOnBind ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD; + description.initialLayout = clearOnBind ? VK_IMAGE_LAYOUT_UNDEFINED : d->initialLayout(); description.finalLayout = d->finalLayout(); attachmentDescriptions.push_back(description); diff --git a/worldeditor/src/screens/scenecomposer/objectcontroller.cpp b/worldeditor/src/screens/scenecomposer/objectcontroller.cpp index 31706cdeb..7f0b40fea 100644 --- a/worldeditor/src/screens/scenecomposer/objectcontroller.cpp +++ b/worldeditor/src/screens/scenecomposer/objectcontroller.cpp @@ -79,6 +79,7 @@ class ViewportRaycast : public PipelineTask { m_resultTarget->setColorAttachment(0, m_resultTexture); m_resultTarget->setDepthAttachment(m_depth); + m_resultTarget->setClearFlags(RenderTarget::ClearColor | RenderTarget::ClearDepth); } void exec() override { @@ -86,7 +87,6 @@ class ViewportRaycast : public PipelineTask { buffer->beginDebugMarker("ViewportRaycast"); buffer->setRenderTarget(m_resultTarget); - buffer->clearRenderTarget(); if(!m_controller->isPickingBlocked() && !m_controller->isPickingOverlaped()) { m_context->drawRenderers(m_context->culledComponents(), CommandBuffer::RAYCAST, Actor::SELECTABLE);