diff --git a/libraries/gpu/src/gpu/Backend.cpp b/libraries/gpu/src/gpu/Backend.cpp index 7859a86824..eb02e15676 100644 --- a/libraries/gpu/src/gpu/Backend.cpp +++ b/libraries/gpu/src/gpu/Backend.cpp @@ -120,8 +120,6 @@ const Backend::TransformCamera& Backend::TransformCamera::recomputeDerived(const viewUntranslated[3] = Vec4(0.0f, 0.0f, 0.0f, 1.0f); _previousProjectionViewUntranslated = previousProjection * viewUntranslated; - //_previousProjectionViewUntranslated = _projection * viewUntranslated; - _stereoInfo = Vec4(0.0f); return *this; diff --git a/libraries/graphics/src/graphics/skybox.slf b/libraries/graphics/src/graphics/skybox.slf index eb34488d50..9bd130a66f 100755 --- a/libraries/graphics/src/graphics/skybox.slf +++ b/libraries/graphics/src/graphics/skybox.slf @@ -10,8 +10,6 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -<@include graphics/ShaderConstants.h@> - <@include skybox.slh@> <@if HIFI_USE_FORWARD@> @@ -63,7 +61,7 @@ void main(void) { _fragColor.rgb = mix(_fragColor.rgb, hazeColor.rgb, hazeColor.a); } <@else@> - packDeferredFragmentSky(_prevPositionCS, color, normal); + packDeferredFragmentSky(_prevPositionCS, color); <@endif@> } diff --git a/libraries/graphics/src/graphics/skybox.slh b/libraries/graphics/src/graphics/skybox.slh index 6bb8570aad..d6dfc8046e 100644 --- a/libraries/graphics/src/graphics/skybox.slh +++ b/libraries/graphics/src/graphics/skybox.slh @@ -11,6 +11,8 @@ <@if not SKYBOX_SLH@> <@def SKYBOX_SLH@> +<@include graphics/ShaderConstants.h@> + <@include gpu/Transform.slh@> <$declareStandardCameraTransform()$> @@ -45,19 +47,12 @@ vec2 packVelocity(vec4 prevPositionCS) { return deltaUV; } -// Must match layout in DeferredBufferWrite.slh, but only velocity and lighting are used -layout(location = 0) out vec4 _albedoMetallic; // albedo / metallic -layout(location = 1) out vec4 _normalRoughness; // normal / roughness -layout(location = 2) out vec4 _scatteringEmissiveOcclusion; // scattering / emissive / occlusion -layout(location = 3) out vec4 _velocity; // velocity -layout(location = 4) out vec4 _lighting; // emissive +layout(location = 0) out vec4 _lighting; // calculated lighting +layout(location = 1) out vec4 _velocity; // velocity -void packDeferredFragmentSky(vec4 prevPositionCS, vec3 color, vec3 normal) { - _albedoMetallic = vec4(color, 0.6f); - _normalRoughness = vec4(packNormal(normal), 1.0f); - _scatteringEmissiveOcclusion = vec4(0.0f); - _velocity = vec4(packVelocity(prevPositionCS), 0.0f, 0.0f); +void packDeferredFragmentSky(vec4 prevPositionCS, vec3 color) { _lighting = vec4(color, 1.0f); + _velocity = vec4(packVelocity(prevPositionCS), 0.0f, 0.0f); } <@endfunc@> diff --git a/libraries/procedural/src/procedural/proceduralSkybox.slf b/libraries/procedural/src/procedural/proceduralSkybox.slf index 3070d5d643..f7b40d22cc 100644 --- a/libraries/procedural/src/procedural/proceduralSkybox.slf +++ b/libraries/procedural/src/procedural/proceduralSkybox.slf @@ -11,8 +11,6 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -<@include graphics/ShaderConstants.h@> - <@include graphics/skybox.slh@> <$declarePackDeferredFragmentSky()$> @@ -37,5 +35,5 @@ void main(void) { // Procedural Shaders are expected to be Gamma corrected so let's bring back the RGB in linear space for the rest of the pipeline color = pow(color, vec3(2.2)); - packDeferredFragmentSky(_prevPositionCS, color, _normal); + packDeferredFragmentSky(_prevPositionCS, color); } diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index 9213bc2fcd..ff965d9eb9 100644 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -15,7 +15,6 @@ <@include DeferredBuffer.slh@> <@include DeferredBufferWrite_shared.slh@> -// Must match layout in skybox.slh layout(location = DEFERRED_COLOR_SLOT) out vec4 _albedoMetallic; // albedo / metallic layout(location = DEFERRED_NORMAL_SLOT) out vec4 _normalRoughness; // normal / roughness layout(location = DEFERRED_SPECULAR_SLOT) out vec4 _scatteringEmissiveOcclusion; // scattering / emissive / occlusion diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 8f7ab0cb02..d9914c63a0 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -287,7 +287,6 @@ void PrepareDeferred::run(const RenderContextPointer& renderContext, const Input outputs.edit0() = _deferredFramebuffer; outputs.edit1() = _deferredFramebuffer->getLightingFramebuffer(); - outputs.edit2() = _deferredFramebuffer->getLightingWithVelocityFramebuffer(); gpu::doInBatch("PrepareDeferred::run", args->_context, [&](gpu::Batch& batch) { batch.enableStereo(false); @@ -507,7 +506,7 @@ void RenderDeferredLocals::run(const render::RenderContextPointer& renderContext } } -void RenderDeferredCleanup::run(const render::RenderContextPointer& renderContext) { +void RenderDeferredCleanup::run(const render::RenderContextPointer& renderContext, const DeferredFramebufferPointer& deferredFramebuffer) { auto args = renderContext->args; auto& batch = (*args->_batch); { @@ -532,6 +531,8 @@ void RenderDeferredCleanup::run(const render::RenderContextPointer& renderContex batch.setUniformBuffer(ru::Buffer::LightClusterGrid, nullptr); batch.setUniformBuffer(ru::Buffer::LightClusterContent, nullptr); + // Restore the lighting with velocity framebuffer so that following stages, like drawing the background, can get motion vectors. + batch.setFramebuffer(deferredFramebuffer->getLightingWithVelocityFramebuffer()); } } @@ -572,7 +573,7 @@ void RenderDeferred::run(const RenderContextPointer& renderContext, const Inputs lightsJob.run(renderContext, deferredTransform, deferredFramebuffer, lightingModel, surfaceGeometryFramebuffer, lightClusters); - cleanupJob.run(renderContext); + cleanupJob.run(renderContext, deferredFramebuffer); _gpuTimer->end(batch); }); diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index a83be6e5d2..b90f3309dd 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -78,7 +78,7 @@ class PrepareDeferred { public: // Inputs: primaryFramebuffer and lightingModel using Inputs = render::VaryingSet2 ; - using Outputs = render::VaryingSet3; + using Outputs = render::VaryingSet2; using JobModel = render::Job::ModelIO; @@ -122,8 +122,8 @@ public: class RenderDeferredCleanup { public: using JobModel = render::Job::Model; - - void run(const render::RenderContextPointer& renderContext); + + void run(const render::RenderContextPointer& renderContext, const DeferredFramebufferPointer& deferredFramebuffer); }; using RenderDeferredConfig = render::GPUJobConfig; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index bbd42596a1..0e0244a91a 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -153,7 +153,6 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto prepareDeferredOutputs = task.addJob("PrepareDeferred", prepareDeferredInputs); const auto deferredFramebuffer = prepareDeferredOutputs.getN(0); const auto lightingFramebuffer = prepareDeferredOutputs.getN(1); - const auto lightingWithVelocityFramebuffer = prepareDeferredOutputs.getN(2); // draw a stencil mask in hidden regions of the framebuffer. task.addJob("PrepareStencil", scaledPrimaryFramebuffer); diff --git a/libraries/render/src/render/DrawSceneOctree.cpp b/libraries/render/src/render/DrawSceneOctree.cpp index 41472e8b18..16b034b6e9 100644 --- a/libraries/render/src/render/DrawSceneOctree.cpp +++ b/libraries/render/src/render/DrawSceneOctree.cpp @@ -61,6 +61,7 @@ const gpu::PipelinePointer DrawSceneOctree::getDrawLODReticlePipeline() { void DrawSceneOctree::configure(const Config& config) { _showVisibleCells = config.showVisibleCells; _showEmptyCells = config.showEmptyCells; + _showLODReticle = config.showLODReticle; } @@ -76,45 +77,48 @@ void DrawSceneOctree::run(const RenderContextPointer& renderContext, const ItemS gpu::doInBatch("DrawSceneOctree::run", args->_context, [&](gpu::Batch& batch) { batch.setViewportTransform(args->_viewport); batch.setSavedViewProjectionTransform(_transformSlot); - batch.setModelTransform(Transform()); - // bind the one gpu::Pipeline we need - batch.setPipeline(getDrawCellBoundsPipeline()); - batch.setInputFormat(_cellBoundsFormat); + if (_showEmptyCells || _showVisibleCells) { + batch.setModelTransform(Transform()); - std::vector cellBounds; - auto drawCellBounds = [this, &cellBounds, &scene](const std::vector& cells) { - cellBounds.reserve(cellBounds.size() + cells.size()); - for (const auto& cellID : cells) { - auto cell = scene->getSpatialTree().getConcreteCell(cellID); - auto cellLoc = cell.getlocation(); - glm::ivec4 cellLocation(cellLoc.pos.x, cellLoc.pos.y, cellLoc.pos.z, cellLoc.depth); + // bind the one gpu::Pipeline we need + batch.setPipeline(getDrawCellBoundsPipeline()); + batch.setInputFormat(_cellBoundsFormat); - bool empty = cell.isBrickEmpty() || !cell.hasBrick(); - if (empty) { - if (!_showEmptyCells) { + std::vector cellBounds; + auto drawCellBounds = [this, &cellBounds, &scene](const std::vector& cells) { + cellBounds.reserve(cellBounds.size() + cells.size()); + for (const auto& cellID : cells) { + auto cell = scene->getSpatialTree().getConcreteCell(cellID); + auto cellLoc = cell.getlocation(); + glm::ivec4 cellLocation(cellLoc.pos.x, cellLoc.pos.y, cellLoc.pos.z, cellLoc.depth); + + bool empty = cell.isBrickEmpty() || !cell.hasBrick(); + if (empty) { + if (!_showEmptyCells) { + continue; + } + cellLocation.w *= -1.0; + } else if (!_showVisibleCells) { continue; } - cellLocation.w *= -1.0; - } else if (!empty && !_showVisibleCells) { - continue; + cellBounds.push_back(cellLocation); } - cellBounds.push_back(cellLocation); - } - }; + }; - drawCellBounds(inSelection.cellSelection.insideCells); - drawCellBounds(inSelection.cellSelection.partialCells); - auto size = cellBounds.size() * sizeof(ivec4); - if (size > _cellBoundsBuffer->getSize()) { - _cellBoundsBuffer->resize(size); + drawCellBounds(inSelection.cellSelection.insideCells); + drawCellBounds(inSelection.cellSelection.partialCells); + auto size = cellBounds.size() * sizeof(ivec4); + if (size > _cellBoundsBuffer->getSize()) { + _cellBoundsBuffer->resize(size); + } + _cellBoundsBuffer->setSubData(0, cellBounds); + batch.setInputBuffer(0, _cellBoundsBuffer, 0, sizeof(ivec4)); + batch.drawInstanced((uint32_t)cellBounds.size(), gpu::LINES, 24); } - _cellBoundsBuffer->setSubData(0, cellBounds); - batch.setInputBuffer(0, _cellBoundsBuffer, 0, sizeof(ivec4)); - batch.drawInstanced((uint32_t)cellBounds.size(), gpu::LINES, 24); // Draw the LOD Reticle - { + if (_showLODReticle) { float angle = glm::degrees(getPerspectiveAccuracyHalfAngle(args->_sizeScale, args->_boundaryLevelAdjust)); Transform crosshairModel; crosshairModel.setTranslation(glm::vec3(0.0, 0.0, -1000.0)); diff --git a/libraries/render/src/render/DrawSceneOctree.h b/libraries/render/src/render/DrawSceneOctree.h index dc9c105d13..8b524ef032 100644 --- a/libraries/render/src/render/DrawSceneOctree.h +++ b/libraries/render/src/render/DrawSceneOctree.h @@ -23,6 +23,7 @@ namespace render { Q_OBJECT Q_PROPERTY(bool showVisibleCells READ getShowVisibleCells WRITE setShowVisibleCells NOTIFY dirty()) Q_PROPERTY(bool showEmptyCells READ getShowEmptyCells WRITE setShowEmptyCells NOTIFY dirty()) + Q_PROPERTY(bool showLODReticle READ getShowLODReticle WRITE setShowLODReticle NOTIFY dirty()) Q_PROPERTY(int numAllocatedCells READ getNumAllocatedCells) Q_PROPERTY(int numFreeCells READ getNumFreeCells) @@ -36,15 +37,18 @@ namespace render { int getNumAllocatedCells() const { return numAllocatedCells; } int getNumFreeCells() const { return numFreeCells; } - bool showVisibleCells{ true }; - bool showEmptyCells{ false }; + bool showVisibleCells { false }; + bool showEmptyCells { false }; + bool showLODReticle { false }; bool getShowVisibleCells() { return showVisibleCells; } bool getShowEmptyCells() { return showEmptyCells; } + bool getShowLODReticle() { return showLODReticle; } public slots: void setShowVisibleCells(bool show) { showVisibleCells = show; emit dirty(); } void setShowEmptyCells(bool show) { showEmptyCells = show; emit dirty(); } + void setShowLODReticle(bool show) { showLODReticle = show; emit dirty(); } signals: void dirty(); @@ -57,8 +61,10 @@ namespace render { gpu::BufferPointer _cellBoundsBuffer; gpu::Stream::FormatPointer _cellBoundsFormat; - bool _showVisibleCells; // initialized by Config - bool _showEmptyCells; // initialized by Config + // initialized by Config + bool _showVisibleCells; + bool _showEmptyCells; + bool _showLODReticle; public: using Config = DrawSceneOctreeConfig; diff --git a/scripts/developer/utilities/render/lod.qml b/scripts/developer/utilities/render/lod.qml index 6497fb967e..3d4cafdd38 100644 --- a/scripts/developer/utilities/render/lod.qml +++ b/scripts/developer/utilities/render/lod.qml @@ -22,8 +22,7 @@ Item { anchors.fill:parent Component.onCompleted: { - Render.getConfig("RenderMainView.DrawSceneOctree").showVisibleCells = false - Render.getConfig("RenderMainView.DrawSceneOctree").showEmptyCells = false + Render.getConfig("RenderMainView.DrawSceneOctree").enabled = true } Component.onDestruction: { @@ -38,9 +37,9 @@ Item { HifiControls.CheckBox { boxSize: 20 - text: "Show LOD Reticule" - checked: Render.getConfig("RenderMainView.DrawSceneOctree").enabled - onCheckedChanged: { Render.getConfig("RenderMainView.DrawSceneOctree").enabled = checked } + text: "Show LOD Reticle" + checked: Render.getConfig("RenderMainView.DrawSceneOctree").showLODReticle + onCheckedChanged: { Render.getConfig("RenderMainView.DrawSceneOctree").showLODReticle = checked } } RichSlider {