From b7b8e8e6bf5761d1df99660cf7f24f9a98dd79fd Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 26 Nov 2018 00:38:04 -0800 Subject: [PATCH 01/31] Trying to group together the debug jobs in a separate task --- .../render-utils/src/RenderDeferredTask.cpp | 90 ++++++++++++++++++- .../render-utils/src/RenderDeferredTask.h | 22 +++++ 2 files changed, 111 insertions(+), 1 deletion(-) diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 4052b6bd5a..bb5ad82a03 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -71,7 +71,6 @@ namespace gr { using graphics::slot::buffer::Buffer; } - RenderDeferredTask::RenderDeferredTask() { } @@ -257,6 +256,8 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren task.addJob("ToneMapping", toneMappingInputs); { // Debug the bounds of the rendered items, still look at the zbuffer + const auto debugInputs = RenderDeferredTaskDebug::Inputs(items.get0(), items.get1(), zones, selectedItems, lightFrame, deferredFramebuffer, lightingFramebuffer, deferredFrameTransform, jitter).asVarying(); + task.addJob("DebugRenderDeferred", input); task.addJob("DrawMetaBounds", metas); task.addJob("DrawOpaqueBounds", opaques); task.addJob("DrawTransparentBounds", transparents); @@ -347,6 +348,93 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren task.addJob("Blit", primaryFramebuffer); } +RenderDeferredTaskDebug::RenderDeferredTaskDebug() { + +} + +void RenderDeferredTaskDebug::configure(const Config& config) { + +} + +void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& inputs, render::Varying& outputs) { + const auto& inputs = input.get(); + const auto& items = inputs.get0(); + + // Extract opaques / transparents / lights / metas / overlays / background + const auto& opaques = items.get0()[RenderFetchCullSortTask::OPAQUE_SHAPE]; + const auto& transparents = items.get0()[RenderFetchCullSortTask::TRANSPARENT_SHAPE]; + const auto& lights = items.get0()[RenderFetchCullSortTask::LIGHT]; + const auto& metas = items.get0()[RenderFetchCullSortTask::META]; + const auto& overlayOpaques = items.get0()[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; + const auto& overlayTransparents = items.get0()[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; + + { // Debug the bounds of the rendered items, still look at the zbuffer + task.addJob("DrawMetaBounds", metas); + task.addJob("DrawOpaqueBounds", opaques); + task.addJob("DrawTransparentBounds", transparents); + + task.addJob("DrawLightBounds", lights); + task.addJob("DrawZones", zones); + const auto frustums = task.addJob("ExtractFrustums", lightFrame); + const auto viewFrustum = frustums.getN(ExtractFrustums::VIEW_FRUSTUM); + task.addJob("DrawViewFrustum", viewFrustum, glm::vec3(0.0f, 1.0f, 0.0f)); + for (auto i = 0; i < ExtractFrustums::SHADOW_CASCADE_FRUSTUM_COUNT; i++) { + const auto shadowFrustum = frustums.getN(ExtractFrustums::SHADOW_CASCADE0_FRUSTUM + i); + float tint = 1.0f - i / float(ExtractFrustums::SHADOW_CASCADE_FRUSTUM_COUNT - 1); + char jobName[64]; + sprintf(jobName, "DrawShadowFrustum%d", i); + task.addJob(jobName, shadowFrustum, glm::vec3(0.0f, tint, 1.0f)); + if (!inputs[1].isNull()) { + const auto& shadowCascadeSceneBBoxes = inputs.get1(); + const auto shadowBBox = shadowCascadeSceneBBoxes[ExtractFrustums::SHADOW_CASCADE0_FRUSTUM + i]; + sprintf(jobName, "DrawShadowBBox%d", i); + task.addJob(jobName, shadowBBox, glm::vec3(1.0f, tint, 0.0f)); + } + } + + // Render.getConfig("RenderMainView.DrawSelectionBounds").enabled = true + task.addJob("DrawSelectionBounds", selectedItems); + } + + { // Debug the bounds of the rendered Overlay items that are marked drawInFront, still look at the zbuffer + task.addJob("DrawOverlayInFrontOpaqueBounds", overlaysInFrontOpaque); + task.addJob("DrawOverlayInFrontTransparentBounds", overlaysInFrontTransparent); + } + + // Debugging stages + { + // Debugging Deferred buffer job + const auto debugFramebuffers = render::Varying(DebugDeferredBuffer::Inputs(deferredFramebuffer, linearDepthTarget, surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, velocityBuffer, deferredFrameTransform, lightFrame)); + task.addJob("DebugDeferredBuffer", debugFramebuffers); + + const auto debugSubsurfaceScatteringInputs = DebugSubsurfaceScattering::Inputs(deferredFrameTransform, deferredFramebuffer, lightingModel, + surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, scatteringResource).asVarying(); + task.addJob("DebugScattering", debugSubsurfaceScatteringInputs); + + const auto debugAmbientOcclusionInputs = DebugAmbientOcclusion::Inputs(deferredFrameTransform, deferredFramebuffer, linearDepthTarget, ambientOcclusionUniforms).asVarying(); + task.addJob("DebugAmbientOcclusion", debugAmbientOcclusionInputs); + + // Scene Octree Debugging job + { + task.addJob("DrawSceneOctree", spatialSelection); + task.addJob("DrawItemSelection", spatialSelection); + } + + // Status icon rendering job + { + // Grab a texture map representing the different status icons and assign that to the drawStatsuJob + auto iconMapPath = PathUtils::resourcesPath() + "icons/statusIconAtlas.svg"; + auto statusIconMap = DependencyManager::get()->getImageTexture(iconMapPath, image::TextureUsage::STRICT_TEXTURE); + const auto drawStatusInputs = DrawStatus::Input(opaques, jitter).asVarying(); + task.addJob("DrawStatus", drawStatusInputs, DrawStatus(statusIconMap)); + } + + const auto debugZoneInputs = DebugZoneLighting::Inputs(deferredFrameTransform, lightFrame, backgroundFrame).asVarying(); + task.addJob("DrawZoneStack", debugZoneInputs); + } +} + + void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs& inputs) { assert(renderContext->args); assert(renderContext->args->hasViewFrustum()); diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index c18daa6d3d..a72cf94b68 100644 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -154,4 +154,26 @@ private: const render::Varying& transparents); }; + +class RenderDeferredTaskDebugConfig : public render::Task::Config { + Q_OBJECT +public: + +signals: + void dirty(); +}; + +class RenderDeferredTaskDebug { +public: + using Input = render::VaryingSet2; + using Config = RenderDeferredTaskConfig; + using JobModel = render::Task::ModelI; + + RenderDeferredTaskDebug(); + + void configure(const Config& config); + void build(JobModel& task, const render::Varying& inputs, render::Varying& outputs); + +private: +}; #endif // hifi_RenderDeferredTask_h From f348cc35c4386068fb3d05560c06610b80afca0b Mon Sep 17 00:00:00 2001 From: sam gateau Date: Mon, 26 Nov 2018 15:20:45 -0800 Subject: [PATCH 02/31] separting debug in its own task --- .../render-utils/src/RenderDeferredTask.cpp | 140 +++++++++++++----- .../render-utils/src/RenderDeferredTask.h | 22 --- libraries/render-utils/src/ZoneRenderer.h | 3 +- libraries/render/src/render/FilterTask.h | 3 +- libraries/task/src/task/Varying.h | 42 ++++++ .../utilities/lib/jet/qml/TaskListView.qml | 2 +- 6 files changed, 153 insertions(+), 59 deletions(-) diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index bb5ad82a03..731ab38467 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -71,6 +71,33 @@ namespace gr { using graphics::slot::buffer::Buffer; } + +/* +class RenderDeferredTaskDebugConfig : public render::Task::Config { + +public: + + signals : + void dirty(); +};*/ + +class RenderDeferredTaskDebug { +public: + using Input = render::VaryingSet8; + // using Config = RenderDeferredTaskConfig; + using JobModel = render::Task::ModelI; + + RenderDeferredTaskDebug(); + + // void configure(const Config& config); + void build(JobModel& task, const render::Varying& inputs, render::Varying& outputs); + +private: +}; + + RenderDeferredTask::RenderDeferredTask() { } @@ -99,7 +126,10 @@ const render::Varying RenderDeferredTask::addSelectItemJobs(JobModel& task, cons void RenderDeferredTask::build(JobModel& task, const render::Varying& input, render::Varying& output, bool renderShadows) { const auto& inputs = input.get(); - const auto& items = inputs.get0(); + const auto& fetchedItems = inputs.get0(); + // const auto& fetchedItems = inputs[0]; + // const auto& items = fetchedItems[0]; + const auto& items = fetchedItems.get0(); auto fadeEffect = DependencyManager::get(); @@ -108,14 +138,22 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren initDeferredPipelines(*shapePlumber, fadeEffect->getBatchSetter(), fadeEffect->getItemUniformSetter()); // Extract opaques / transparents / lights / metas / overlays / background - const auto& opaques = items.get0()[RenderFetchCullSortTask::OPAQUE_SHAPE]; + /* const auto& opaques = items.get0()[RenderFetchCullSortTask::OPAQUE_SHAPE]; const auto& transparents = items.get0()[RenderFetchCullSortTask::TRANSPARENT_SHAPE]; const auto& lights = items.get0()[RenderFetchCullSortTask::LIGHT]; const auto& metas = items.get0()[RenderFetchCullSortTask::META]; const auto& overlayOpaques = items.get0()[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; const auto& overlayTransparents = items.get0()[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; - //const auto& background = items.get0()[RenderFetchCullSortTask::BACKGROUND]; - const auto& spatialSelection = items[1]; +*/ + const auto& opaques = items[RenderFetchCullSortTask::OPAQUE_SHAPE]; + const auto& transparents = items[RenderFetchCullSortTask::TRANSPARENT_SHAPE]; + const auto& lights = items[RenderFetchCullSortTask::LIGHT]; + const auto& metas = items[RenderFetchCullSortTask::META]; + const auto& overlayOpaques = items[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; + const auto& overlayTransparents = items[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; + +//const auto& background = items.get0()[RenderFetchCullSortTask::BACKGROUND]; + const auto& spatialSelection = fetchedItems[1]; fadeEffect->build(task, opaques); @@ -180,11 +218,11 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren task.addJob("DrawLight", lights); // Fetch the current frame stacks from all the stages - const auto currentFrames = task.addJob("FetchCurrentFrames"); - const auto lightFrame = currentFrames.getN(0); - const auto backgroundFrame = currentFrames.getN(1); - const auto hazeFrame = currentFrames.getN(2); - const auto bloomFrame = currentFrames.getN(3); + const auto currentStageFrames = task.addJob("FetchCurrentFrames"); + const auto lightFrame = currentStageFrames.getN(0); + const auto backgroundFrame = currentStageFrames.getN(1); + const auto hazeFrame = currentStageFrames.getN(2); + const auto bloomFrame = currentStageFrames.getN(3); // Light Clustering // Create the cluster grid of lights, cpu job for now @@ -218,7 +256,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto selectionBaseName = "contextOverlayHighlightList"; const auto selectedItems = addSelectItemJobs(task, selectionBaseName, metas, opaques, transparents); - const auto outlineInputs = DrawHighlightTask::Inputs(items.get0(), deferredFramebuffer, lightingFramebuffer, deferredFrameTransform, jitter).asVarying(); + const auto outlineInputs = DrawHighlightTask::Inputs(items, deferredFramebuffer, lightingFramebuffer, deferredFrameTransform, jitter).asVarying(); task.addJob("DrawHighlight", outlineInputs); task.addJob("HighlightRangeTimer", outlineRangeTimer); @@ -256,9 +294,9 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren task.addJob("ToneMapping", toneMappingInputs); { // Debug the bounds of the rendered items, still look at the zbuffer - const auto debugInputs = RenderDeferredTaskDebug::Inputs(items.get0(), items.get1(), zones, selectedItems, lightFrame, deferredFramebuffer, lightingFramebuffer, deferredFrameTransform, jitter).asVarying(); - task.addJob("DebugRenderDeferred", input); - task.addJob("DrawMetaBounds", metas); + const auto debugInputs = RenderDeferredTaskDebug::Input(items, inputs[1], zones, selectedItems, currentStageFrames, prepareDeferredOutputs, deferredFrameTransform, jitter).asVarying(); + task.addJob("DebugRenderDeferredTask", input); + /*task.addJob("DrawMetaBounds", metas); task.addJob("DrawOpaqueBounds", opaques); task.addJob("DrawTransparentBounds", transparents); @@ -282,7 +320,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren } // Render.getConfig("RenderMainView.DrawSelectionBounds").enabled = true - task.addJob("DrawSelectionBounds", selectedItems); + task.addJob("DrawSelectionBounds", selectedItems);*/ } { // Debug the bounds of the rendered Overlay items that are marked drawInFront, still look at the zbuffer @@ -302,7 +340,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto debugAmbientOcclusionInputs = DebugAmbientOcclusion::Inputs(deferredFrameTransform, deferredFramebuffer, linearDepthTarget, ambientOcclusionUniforms).asVarying(); task.addJob("DebugAmbientOcclusion", debugAmbientOcclusionInputs); - +/* // Scene Octree Debugging job { task.addJob("DrawSceneOctree", spatialSelection); @@ -319,7 +357,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren } const auto debugZoneInputs = DebugZoneLighting::Inputs(deferredFrameTransform, lightFrame, backgroundFrame).asVarying(); - task.addJob("DrawZoneStack", debugZoneInputs); + task.addJob("DrawZoneStack", debugZoneInputs);*/ } // Upscale to finale resolution @@ -351,22 +389,56 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren RenderDeferredTaskDebug::RenderDeferredTaskDebug() { } - +/* void RenderDeferredTaskDebug::configure(const Config& config) { -} +}*/ + +void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input, render::Varying& outputs) { +// RenderFetchCullSortTask::Output, RenderShadowTask::Output, +// ZoneRendererTask::Outputs, SelectItems::Outputs, FetchCurrentFrames::Outputs, +// PrepareDeferred::Outputs, GenerateDeferredFrameTransform::Output, JitterSample::Output -void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& inputs, render::Varying& outputs) { const auto& inputs = input.get(); - const auto& items = inputs.get0(); - // Extract opaques / transparents / lights / metas / overlays / background - const auto& opaques = items.get0()[RenderFetchCullSortTask::OPAQUE_SHAPE]; - const auto& transparents = items.get0()[RenderFetchCullSortTask::TRANSPARENT_SHAPE]; - const auto& lights = items.get0()[RenderFetchCullSortTask::LIGHT]; - const auto& metas = items.get0()[RenderFetchCullSortTask::META]; - const auto& overlayOpaques = items.get0()[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; - const auto& overlayTransparents = items.get0()[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; + // RenderFetchCullSortTask out + const auto& fetchCullSortTaskOut = inputs.get0(); + const auto& items = fetchCullSortTaskOut.get0(); + const auto& spatialSelection = fetchCullSortTaskOut[1]; + + // Extract opaques / transparents / lights / metas / overlays / background + const auto& opaques = items[RenderFetchCullSortTask::OPAQUE_SHAPE]; + const auto& transparents = items[RenderFetchCullSortTask::TRANSPARENT_SHAPE]; + const auto& lights = items[RenderFetchCullSortTask::LIGHT]; + const auto& metas = items[RenderFetchCullSortTask::META]; + const auto& overlayOpaques = items[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; + const auto& overlayTransparents = items[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; + + // RenderShadowTask out + const auto& renderShadowTaskOut = inputs[1]; + + // Zones + const auto& zones = inputs[2]; + + // Selected objects + const auto& selectedItems = inputs[3]; + + // Stage current frames + const auto& stageCurrentFrames = inputs.get4();//[4]; + const auto lightFrame = stageCurrentFrames[0]; + const auto backgroundFrame = stageCurrentFrames[1]; + const auto hazeFrame = stageCurrentFrames[2]; + const auto bloomFrame = stageCurrentFrames[3]; + + // PrepareDeferred out + const auto& deferredFramebuffer = inputs[5]; + + // GenerateDeferredFrameTransform out + const auto& deferredFrameTransform = inputs[6]; + + // Jitter out + const auto& jitter = inputs[7]; + { // Debug the bounds of the rendered items, still look at the zbuffer task.addJob("DrawMetaBounds", metas); @@ -384,8 +456,8 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input char jobName[64]; sprintf(jobName, "DrawShadowFrustum%d", i); task.addJob(jobName, shadowFrustum, glm::vec3(0.0f, tint, 1.0f)); - if (!inputs[1].isNull()) { - const auto& shadowCascadeSceneBBoxes = inputs.get1(); + if (!renderShadowTaskOut.isNull()) { + const auto& shadowCascadeSceneBBoxes = renderShadowTaskOut; const auto shadowBBox = shadowCascadeSceneBBoxes[ExtractFrustums::SHADOW_CASCADE0_FRUSTUM + i]; sprintf(jobName, "DrawShadowBBox%d", i); task.addJob(jobName, shadowBBox, glm::vec3(1.0f, tint, 0.0f)); @@ -397,14 +469,14 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input } { // Debug the bounds of the rendered Overlay items that are marked drawInFront, still look at the zbuffer - task.addJob("DrawOverlayInFrontOpaqueBounds", overlaysInFrontOpaque); + /* task.addJob("DrawOverlayInFrontOpaqueBounds", overlaysInFrontOpaque); task.addJob("DrawOverlayInFrontTransparentBounds", overlaysInFrontTransparent); - } + */ } // Debugging stages { // Debugging Deferred buffer job - const auto debugFramebuffers = render::Varying(DebugDeferredBuffer::Inputs(deferredFramebuffer, linearDepthTarget, surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, velocityBuffer, deferredFrameTransform, lightFrame)); + /* const auto debugFramebuffers = render::Varying(DebugDeferredBuffer::Inputs(deferredFramebuffer, linearDepthTarget, surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, velocityBuffer, deferredFrameTransform, lightFrame)); task.addJob("DebugDeferredBuffer", debugFramebuffers); const auto debugSubsurfaceScatteringInputs = DebugSubsurfaceScattering::Inputs(deferredFrameTransform, deferredFramebuffer, lightingModel, @@ -413,7 +485,7 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input const auto debugAmbientOcclusionInputs = DebugAmbientOcclusion::Inputs(deferredFrameTransform, deferredFramebuffer, linearDepthTarget, ambientOcclusionUniforms).asVarying(); task.addJob("DebugAmbientOcclusion", debugAmbientOcclusionInputs); - +*/ // Scene Octree Debugging job { task.addJob("DrawSceneOctree", spatialSelection); @@ -422,7 +494,7 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input // Status icon rendering job { - // Grab a texture map representing the different status icons and assign that to the drawStatsuJob + // Grab a texture map representing the different status icons and assign that to the drawStatusJob auto iconMapPath = PathUtils::resourcesPath() + "icons/statusIconAtlas.svg"; auto statusIconMap = DependencyManager::get()->getImageTexture(iconMapPath, image::TextureUsage::STRICT_TEXTURE); const auto drawStatusInputs = DrawStatus::Input(opaques, jitter).asVarying(); diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index a72cf94b68..c18daa6d3d 100644 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -154,26 +154,4 @@ private: const render::Varying& transparents); }; - -class RenderDeferredTaskDebugConfig : public render::Task::Config { - Q_OBJECT -public: - -signals: - void dirty(); -}; - -class RenderDeferredTaskDebug { -public: - using Input = render::VaryingSet2; - using Config = RenderDeferredTaskConfig; - using JobModel = render::Task::ModelI; - - RenderDeferredTaskDebug(); - - void configure(const Config& config); - void build(JobModel& task, const render::Varying& inputs, render::Varying& outputs); - -private: -}; #endif // hifi_RenderDeferredTask_h diff --git a/libraries/render-utils/src/ZoneRenderer.h b/libraries/render-utils/src/ZoneRenderer.h index 1646c5977d..36d63a98d1 100644 --- a/libraries/render-utils/src/ZoneRenderer.h +++ b/libraries/render-utils/src/ZoneRenderer.h @@ -52,8 +52,9 @@ public: using Inputs = render::ItemBounds; + using Outputs = render::ItemBounds; using Config = ZoneRendererConfig; - using JobModel = render::Task::ModelI; + using JobModel = render::Task::ModelIO; ZoneRendererTask() {} diff --git a/libraries/render/src/render/FilterTask.h b/libraries/render/src/render/FilterTask.h index 9b40728b00..c2244e5f57 100644 --- a/libraries/render/src/render/FilterTask.h +++ b/libraries/render/src/render/FilterTask.h @@ -114,7 +114,8 @@ namespace render { class SelectItems { public: using Inputs = VaryingSet3; - using JobModel = Job::ModelIO; + using Outputs = ItemBounds; + using JobModel = Job::ModelIO; std::string _name; SelectItems() {} diff --git a/libraries/task/src/task/Varying.h b/libraries/task/src/task/Varying.h index 9536db2799..f7dbdfba29 100644 --- a/libraries/task/src/task/Varying.h +++ b/libraries/task/src/task/Varying.h @@ -289,6 +289,26 @@ public: const T6& get6() const { return std::get<6>((*this)).template get(); } T6& edit6() { return std::get<6>((*this)).template edit(); } + virtual Varying operator[] (uint8_t index) const { + switch (index) { + default: + return std::get<0>((*this)); + case 1: + return std::get<1>((*this)); + case 2: + return std::get<2>((*this)); + case 3: + return std::get<3>((*this)); + case 4: + return std::get<4>((*this)); + case 5: + return std::get<5>((*this)); + case 6: + return std::get<6>((*this)); + }; + } + virtual uint8_t length() const { return 7; } + Varying asVarying() const { return Varying((*this)); } }; @@ -325,6 +345,28 @@ public: const T7& get7() const { return std::get<7>((*this)).template get(); } T7& edit7() { return std::get<7>((*this)).template edit(); } + virtual Varying operator[] (uint8_t index) const { + switch (index) { + default: + return std::get<0>((*this)); + case 1: + return std::get<1>((*this)); + case 2: + return std::get<2>((*this)); + case 3: + return std::get<3>((*this)); + case 4: + return std::get<4>((*this)); + case 5: + return std::get<5>((*this)); + case 6: + return std::get<6>((*this)); + case 7: + return std::get<7>((*this)); + }; + } + virtual uint8_t length() const { return 8; } + Varying asVarying() const { return Varying((*this)); } }; diff --git a/scripts/developer/utilities/lib/jet/qml/TaskListView.qml b/scripts/developer/utilities/lib/jet/qml/TaskListView.qml index 0f083aa72c..92488e7333 100644 --- a/scripts/developer/utilities/lib/jet/qml/TaskListView.qml +++ b/scripts/developer/utilities/lib/jet/qml/TaskListView.qml @@ -27,7 +27,7 @@ Rectangle { Component.onCompleted: { var message = "" - var maxDepth = 3; + var maxDepth = 5; var jobTreePath = [] var jobsRoot; From ba4aec2aff76fb21d1fae4048c2424a0595127e2 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Wed, 28 Nov 2018 01:01:18 -0800 Subject: [PATCH 03/31] Fixing the issues with thte debug renderdeferredTask and investigating the avatars perf --- .../render-utils/src/RenderDeferredTask.cpp | 4 +- libraries/task/src/task/Varying.h | 3 +- .../developer/utilities/workload/avatars.js | 129 ++++++++++++++++++ .../developer/utilities/workload/avatars.qml | 78 +++++++++++ 4 files changed, 211 insertions(+), 3 deletions(-) create mode 100644 scripts/developer/utilities/workload/avatars.js create mode 100644 scripts/developer/utilities/workload/avatars.qml diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 731ab38467..01df28d1dd 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -294,8 +294,8 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren task.addJob("ToneMapping", toneMappingInputs); { // Debug the bounds of the rendered items, still look at the zbuffer - const auto debugInputs = RenderDeferredTaskDebug::Input(items, inputs[1], zones, selectedItems, currentStageFrames, prepareDeferredOutputs, deferredFrameTransform, jitter).asVarying(); - task.addJob("DebugRenderDeferredTask", input); + const auto debugInputs = RenderDeferredTaskDebug::Input(fetchedItems, inputs[1], zones, selectedItems, currentStageFrames, prepareDeferredOutputs, deferredFrameTransform, jitter).asVarying(); + task.addJob("DebugRenderDeferredTask", debugInputs); /*task.addJob("DrawMetaBounds", metas); task.addJob("DrawOpaqueBounds", opaques); task.addJob("DrawTransparentBounds", transparents); diff --git a/libraries/task/src/task/Varying.h b/libraries/task/src/task/Varying.h index f7dbdfba29..2da0111bc2 100644 --- a/libraries/task/src/task/Varying.h +++ b/libraries/task/src/task/Varying.h @@ -12,6 +12,7 @@ #ifndef hifi_task_Varying_h #define hifi_task_Varying_h +#include #include #include @@ -23,7 +24,7 @@ public: Varying() {} Varying(const Varying& var) : _concept(var._concept) {} Varying& operator=(const Varying& var) { - _concept = var._concept; + _concept = var._concept; return (*this); } template Varying(const T& data) : _concept(std::make_shared>(data)) {} diff --git a/scripts/developer/utilities/workload/avatars.js b/scripts/developer/utilities/workload/avatars.js new file mode 100644 index 0000000000..3080ef09db --- /dev/null +++ b/scripts/developer/utilities/workload/avatars.js @@ -0,0 +1,129 @@ +"use strict"; + +// +// Avatars.js +// tablet-engine app +// +// Copyright 2018 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +(function() { + var TABLET_BUTTON_NAME = "Avatars"; + var QMLAPP_URL = Script.resolvePath("./avatars.qml"); + var ICON_URL = Script.resolvePath("../../../system/assets/images/lod-i.svg"); + var ACTIVE_ICON_URL = Script.resolvePath("../../../system/assets/images/lod-a.svg"); + + var onTablet = false; // set this to true to use the tablet, false use a floating window + + var onAppScreen = false; + + var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); + var button = tablet.addButton({ + text: TABLET_BUTTON_NAME, + icon: ICON_URL, + activeIcon: ACTIVE_ICON_URL + }); + + var hasEventBridge = false; + + var onScreen = false; + var window; + + function onClicked() { + if (onTablet) { + if (onAppScreen) { + tablet.gotoHomeScreen(); + } else { + tablet.loadQMLSource(QMLAPP_URL); + } + } else { + if (onScreen) { + killWindow() + } else { + createWindow() + } + } + } + + function createWindow() { + var qml = Script.resolvePath(QMLAPP_URL); + window = Desktop.createWindow(Script.resolvePath(QMLAPP_URL), { + title: TABLET_BUTTON_NAME, + flags: Desktop.ALWAYS_ON_TOP, + presentationMode: Desktop.PresentationMode.NATIVE, + size: {x: 400, y: 600} + }); + window.closed.connect(killWindow); + window.fromQml.connect(fromQml); + onScreen = true + button.editProperties({isActive: true}); + } + + function killWindow() { + if (window !== undefined) { + window.closed.disconnect(killWindow); + window.fromQml.disconnect(fromQml); + window.close() + window = undefined + } + onScreen = false + button.editProperties({isActive: false}) + } + + function wireEventBridge(on) { + if (!tablet) { + print("Warning in wireEventBridge(): 'tablet' undefined!"); + return; + } + if (on) { + if (!hasEventBridge) { + tablet.fromQml.connect(fromQml); + hasEventBridge = true; + } + } else { + if (hasEventBridge) { + tablet.fromQml.disconnect(fromQml); + hasEventBridge = false; + } + } + } + + function onScreenChanged(type, url) { + if (onTablet) { + onAppScreen = (url === QMLAPP_URL); + + button.editProperties({isActive: onAppScreen}); + wireEventBridge(onAppScreen); + } + } + + button.clicked.connect(onClicked); + tablet.screenChanged.connect(onScreenChanged); + + Script.scriptEnding.connect(function () { + killWindow() + if (onAppScreen) { + tablet.gotoHomeScreen(); + } + button.clicked.disconnect(onClicked); + tablet.screenChanged.disconnect(onScreenChanged); + tablet.removeButton(button); + }); + + function fromQml(message) { + } + + function sendToQml(message) { + if (onTablet) { + tablet.sendToQml(message); + } else { + if (window) { + window.sendToQml(message); + } + } + } + +}()); diff --git a/scripts/developer/utilities/workload/avatars.qml b/scripts/developer/utilities/workload/avatars.qml new file mode 100644 index 0000000000..5951e72c31 --- /dev/null +++ b/scripts/developer/utilities/workload/avatars.qml @@ -0,0 +1,78 @@ +// +// avatars.qml +// scripts/developer/utilities/workload +// +// Created by Sam Gateau on 2018.11.28 +// Copyright 2018 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html +// +import QtQuick 2.5 +import QtQuick.Controls 1.4 + +import stylesUit 1.0 +import controlsUit 1.0 as HifiControls + +import "../lib/plotperf" +import "../render/configSlider" + +Item { + id: root + anchors.fill:parent + + Component.onCompleted: { + } + + Component.onDestruction: { + } + + Column { + id: topHeader + spacing: 8 + anchors.right: parent.right + anchors.left: parent.left + } + + Column { + id: stats + spacing: 4 + anchors.right: parent.right + anchors.left: parent.left + anchors.top: topHeader.bottom + anchors.bottom: parent.bottom + + function evalEvenHeight() { + // Why do we have to do that manually ? cannot seem to find a qml / anchor / layout mode that does that ? + var numPlots = (children.length + - 2) + return (height - topLine.height - bottomLine.height - spacing * (numPlots - 1)) / (numPlots) + } + + Separator { + id: topLine + } + + PlotPerf { + title: "Avatars" + height: parent.evalEvenHeight() + object: Stats + valueScale: 1 + valueUnit: "num" + plots: [ + { + prop: "updatedAvatarCount", + label: "updatedAvatarCount", + color: "#FFFF00" + }, + { + prop: "notUpdatedAvatarCount", + label: "notUpdatedAvatarCount", + color: "#00FF00" + } + ] + } + Separator { + id: bottomLine + } + } +} From 14bf383c50400d489fc5b28686536c9549cac8f6 Mon Sep 17 00:00:00 2001 From: sam gateau Date: Thu, 29 Nov 2018 17:59:04 -0800 Subject: [PATCH 04/31] MIgrating everything to collect the items out from the render task --- libraries/render/src/render/RenderFetchCullSortTask.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/render/src/render/RenderFetchCullSortTask.h b/libraries/render/src/render/RenderFetchCullSortTask.h index 8c9f2e7304..962191ace4 100644 --- a/libraries/render/src/render/RenderFetchCullSortTask.h +++ b/libraries/render/src/render/RenderFetchCullSortTask.h @@ -25,6 +25,9 @@ public: META, OVERLAY_OPAQUE_SHAPE, OVERLAY_TRANSPARENT_SHAPE, + HUD_OPAQUE_SHAPE, + HUD_TRANSPARENT_SHAPE, + BACKGROUND, NUM_BUCKETS From 2c4cd68a00f5b24522f1252e3f4cf91a75116e5f Mon Sep 17 00:00:00 2001 From: sam gateau Date: Fri, 30 Nov 2018 17:43:27 -0800 Subject: [PATCH 05/31] iterating on a simpler engine graph --- libraries/render-utils/src/RenderDeferredTask.cpp | 9 ++++++++- .../render/src/render/RenderFetchCullSortTask.cpp | 10 +++++++++- libraries/render/src/render/RenderFetchCullSortTask.h | 6 ++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 01df28d1dd..95e1298de8 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -151,7 +151,14 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto& metas = items[RenderFetchCullSortTask::META]; const auto& overlayOpaques = items[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; const auto& overlayTransparents = items[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; - + const auto& overlayOpaques = items[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; + const auto& overlayTransparents = items[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; + const auto& overlaysInFrontOpaque = items[RenderFetchCullSortTask::LAYER_FRONT_OPAQUE_SHAPE]; + const auto& overlaysInFrontTransparent = items[RenderFetchCullSortTask::LAYER_FRONT_TRANSPARENT_SHAPE]; + const auto& overlaysHUDOpaque = items[RenderFetchCullSortTask::LAYER_HUD_OPAQUE_SHAPE]; + const auto& overlaysHUDTransparent = items[RenderFetchCullSortTask::LAYER_HUD_TRANSPARENT_SHAPE]; + + //const auto& background = items.get0()[RenderFetchCullSortTask::BACKGROUND]; const auto& spatialSelection = fetchedItems[1]; diff --git a/libraries/render/src/render/RenderFetchCullSortTask.cpp b/libraries/render/src/render/RenderFetchCullSortTask.cpp index 7b9765dca1..324f1d879f 100644 --- a/libraries/render/src/render/RenderFetchCullSortTask.cpp +++ b/libraries/render/src/render/RenderFetchCullSortTask.cpp @@ -70,5 +70,13 @@ void RenderFetchCullSortTask::build(JobModel& task, const Varying& input, Varyin const auto overlayTransparents = task.addJob("DepthSortOverlayTransparent", filteredNonspatialBuckets[TRANSPARENT_SHAPE_BUCKET], DepthSortItems(false)); const auto background = filteredNonspatialBuckets[BACKGROUND_BUCKET]; - output = Output(BucketList{ opaques, transparents, lights, metas, overlayOpaques, overlayTransparents, background }, spatialSelection); + // split up the overlays into 3D front, hud + const auto filteredOverlaysOpaque = task.addJob("FilterOverlaysLayeredOpaque", overlayOpaques, ItemKey::Layer::LAYER_1); + const auto filteredOverlaysTransparent = task.addJob("FilterOverlaysLayeredTransparent", overlayTransparents, ItemKey::Layer::LAYER_1); + + + output = Output(BucketList{ opaques, transparents, lights, metas, overlayOpaques, overlayTransparents, + filteredOverlaysOpaque.getN(0), filteredOverlaysTransparent.getN(0), + filteredOverlaysOpaque.getN(1), filteredOverlaysTransparent.getN(1), + background }, spatialSelection); } diff --git a/libraries/render/src/render/RenderFetchCullSortTask.h b/libraries/render/src/render/RenderFetchCullSortTask.h index 962191ace4..a75c814d91 100644 --- a/libraries/render/src/render/RenderFetchCullSortTask.h +++ b/libraries/render/src/render/RenderFetchCullSortTask.h @@ -25,8 +25,10 @@ public: META, OVERLAY_OPAQUE_SHAPE, OVERLAY_TRANSPARENT_SHAPE, - HUD_OPAQUE_SHAPE, - HUD_TRANSPARENT_SHAPE, + LAYER_FRONT_OPAQUE_SHAPE, + LAYER_FRONT_TRANSPARENT_SHAPE, + LAYER_HUD_OPAQUE_SHAPE, + LAYER_HUD_TRANSPARENT_SHAPE, BACKGROUND, From 259a97c43ad46490daf5de8e75a614816f62adb3 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Sun, 2 Dec 2018 23:41:57 -0800 Subject: [PATCH 06/31] Exploring varying with names --- .../render-utils/src/RenderDeferredTask.cpp | 125 ++++-------------- libraries/task/src/task/Task.h | 2 +- libraries/task/src/task/Varying.h | 34 ++++- 3 files changed, 57 insertions(+), 104 deletions(-) diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 95e1298de8..b6565b0c85 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -83,9 +83,9 @@ public: class RenderDeferredTaskDebug { public: - using Input = render::VaryingSet8; + PrepareDeferred::Outputs, GenerateDeferredFrameTransform::Output, JitterSample::Output, LightingModel>; // using Config = RenderDeferredTaskConfig; using JobModel = render::Task::ModelI; @@ -138,28 +138,17 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren initDeferredPipelines(*shapePlumber, fadeEffect->getBatchSetter(), fadeEffect->getItemUniformSetter()); // Extract opaques / transparents / lights / metas / overlays / background - /* const auto& opaques = items.get0()[RenderFetchCullSortTask::OPAQUE_SHAPE]; - const auto& transparents = items.get0()[RenderFetchCullSortTask::TRANSPARENT_SHAPE]; - const auto& lights = items.get0()[RenderFetchCullSortTask::LIGHT]; - const auto& metas = items.get0()[RenderFetchCullSortTask::META]; - const auto& overlayOpaques = items.get0()[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; - const auto& overlayTransparents = items.get0()[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; -*/ const auto& opaques = items[RenderFetchCullSortTask::OPAQUE_SHAPE]; const auto& transparents = items[RenderFetchCullSortTask::TRANSPARENT_SHAPE]; const auto& lights = items[RenderFetchCullSortTask::LIGHT]; const auto& metas = items[RenderFetchCullSortTask::META]; const auto& overlayOpaques = items[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; const auto& overlayTransparents = items[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; - const auto& overlayOpaques = items[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; - const auto& overlayTransparents = items[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; const auto& overlaysInFrontOpaque = items[RenderFetchCullSortTask::LAYER_FRONT_OPAQUE_SHAPE]; const auto& overlaysInFrontTransparent = items[RenderFetchCullSortTask::LAYER_FRONT_TRANSPARENT_SHAPE]; const auto& overlaysHUDOpaque = items[RenderFetchCullSortTask::LAYER_HUD_OPAQUE_SHAPE]; const auto& overlaysHUDTransparent = items[RenderFetchCullSortTask::LAYER_HUD_TRANSPARENT_SHAPE]; - -//const auto& background = items.get0()[RenderFetchCullSortTask::BACKGROUND]; const auto& spatialSelection = fetchedItems[1]; fadeEffect->build(task, opaques); @@ -268,24 +257,12 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren task.addJob("HighlightRangeTimer", outlineRangeTimer); - const auto overlaysInFrontRangeTimer = task.addJob("BeginOverlaysInFrontRangeTimer", "BeginOverlaysInFrontRangeTimer"); - - // Layered Overlays - const auto filteredOverlaysOpaque = task.addJob("FilterOverlaysLayeredOpaque", overlayOpaques, render::hifi::LAYER_3D_FRONT); - const auto filteredOverlaysTransparent = task.addJob("FilterOverlaysLayeredTransparent", overlayTransparents, render::hifi::LAYER_3D_FRONT); - const auto overlaysInFrontOpaque = filteredOverlaysOpaque.getN(0); - const auto overlaysInFrontTransparent = filteredOverlaysTransparent.getN(0); - - // We don't want the overlay to clear the deferred frame buffer depth because we would like to keep it for debugging visualisation - // task.addJob("SeparateDepthForOverlay", deferredFramebuffer); - + // Layered Over (in front) const auto overlayInFrontOpaquesInputs = DrawOverlay3D::Inputs(overlaysInFrontOpaque, lightingModel, jitter).asVarying(); const auto overlayInFrontTransparentsInputs = DrawOverlay3D::Inputs(overlaysInFrontTransparent, lightingModel, jitter).asVarying(); task.addJob("DrawOverlayInFrontOpaque", overlayInFrontOpaquesInputs, true); task.addJob("DrawOverlayInFrontTransparent", overlayInFrontTransparentsInputs, false); - task.addJob("OverlaysInFrontRangeTimer", overlaysInFrontRangeTimer); - const auto toneAndPostRangeTimer = task.addJob("BeginToneAndPostRangeTimer", "PostToneOverlaysAntialiasing"); // AA job before bloom to limit flickering @@ -300,71 +277,10 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto toneMappingInputs = ToneMappingDeferred::Inputs(lightingFramebuffer, scaledPrimaryFramebuffer).asVarying(); task.addJob("ToneMapping", toneMappingInputs); + // Debugging task is happening in the "over" layer after tone mapping and just before HUD { // Debug the bounds of the rendered items, still look at the zbuffer - const auto debugInputs = RenderDeferredTaskDebug::Input(fetchedItems, inputs[1], zones, selectedItems, currentStageFrames, prepareDeferredOutputs, deferredFrameTransform, jitter).asVarying(); + const auto debugInputs = RenderDeferredTaskDebug::Input(fetchedItems, inputs[1], zones, selectedItems, currentStageFrames, prepareDeferredOutputs, deferredFrameTransform, jitter, lightingModel).asVarying(); task.addJob("DebugRenderDeferredTask", debugInputs); - /*task.addJob("DrawMetaBounds", metas); - task.addJob("DrawOpaqueBounds", opaques); - task.addJob("DrawTransparentBounds", transparents); - - task.addJob("DrawLightBounds", lights); - task.addJob("DrawZones", zones); - const auto frustums = task.addJob("ExtractFrustums", lightFrame); - const auto viewFrustum = frustums.getN(ExtractFrustums::VIEW_FRUSTUM); - task.addJob("DrawViewFrustum", viewFrustum, glm::vec3(0.0f, 1.0f, 0.0f)); - for (auto i = 0; i < ExtractFrustums::SHADOW_CASCADE_FRUSTUM_COUNT; i++) { - const auto shadowFrustum = frustums.getN(ExtractFrustums::SHADOW_CASCADE0_FRUSTUM + i); - float tint = 1.0f - i / float(ExtractFrustums::SHADOW_CASCADE_FRUSTUM_COUNT - 1); - char jobName[64]; - sprintf(jobName, "DrawShadowFrustum%d", i); - task.addJob(jobName, shadowFrustum, glm::vec3(0.0f, tint, 1.0f)); - if (!inputs[1].isNull()) { - const auto& shadowCascadeSceneBBoxes = inputs.get1(); - const auto shadowBBox = shadowCascadeSceneBBoxes[ExtractFrustums::SHADOW_CASCADE0_FRUSTUM + i]; - sprintf(jobName, "DrawShadowBBox%d", i); - task.addJob(jobName, shadowBBox, glm::vec3(1.0f, tint, 0.0f)); - } - } - - // Render.getConfig("RenderMainView.DrawSelectionBounds").enabled = true - task.addJob("DrawSelectionBounds", selectedItems);*/ - } - - { // Debug the bounds of the rendered Overlay items that are marked drawInFront, still look at the zbuffer - task.addJob("DrawOverlayInFrontOpaqueBounds", overlaysInFrontOpaque); - task.addJob("DrawOverlayInFrontTransparentBounds", overlaysInFrontTransparent); - } - - // Debugging stages - { - // Debugging Deferred buffer job - const auto debugFramebuffers = render::Varying(DebugDeferredBuffer::Inputs(deferredFramebuffer, linearDepthTarget, surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, velocityBuffer, deferredFrameTransform, lightFrame)); - task.addJob("DebugDeferredBuffer", debugFramebuffers); - - const auto debugSubsurfaceScatteringInputs = DebugSubsurfaceScattering::Inputs(deferredFrameTransform, deferredFramebuffer, lightingModel, - surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, scatteringResource).asVarying(); - task.addJob("DebugScattering", debugSubsurfaceScatteringInputs); - - const auto debugAmbientOcclusionInputs = DebugAmbientOcclusion::Inputs(deferredFrameTransform, deferredFramebuffer, linearDepthTarget, ambientOcclusionUniforms).asVarying(); - task.addJob("DebugAmbientOcclusion", debugAmbientOcclusionInputs); -/* - // Scene Octree Debugging job - { - task.addJob("DrawSceneOctree", spatialSelection); - task.addJob("DrawItemSelection", spatialSelection); - } - - // Status icon rendering job - { - // Grab a texture map representing the different status icons and assign that to the drawStatsuJob - auto iconMapPath = PathUtils::resourcesPath() + "icons/statusIconAtlas.svg"; - auto statusIconMap = DependencyManager::get()->getImageTexture(iconMapPath, image::TextureUsage::STRICT_TEXTURE); - const auto drawStatusInputs = DrawStatus::Input(opaques, jitter).asVarying(); - task.addJob("DrawStatus", drawStatusInputs, DrawStatus(statusIconMap)); - } - - const auto debugZoneInputs = DebugZoneLighting::Inputs(deferredFrameTransform, lightFrame, backgroundFrame).asVarying(); - task.addJob("DrawZoneStack", debugZoneInputs);*/ } // Upscale to finale resolution @@ -373,20 +289,12 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren // Composite the HUD and HUD overlays task.addJob("HUD"); - const auto overlaysHUDOpaque = filteredOverlaysOpaque.getN(1); - const auto overlaysHUDTransparent = filteredOverlaysTransparent.getN(1); const auto nullJitter = Varying(glm::vec2(0.0f, 0.0f)); - const auto overlayHUDOpaquesInputs = DrawOverlay3D::Inputs(overlaysHUDOpaque, lightingModel, nullJitter).asVarying(); const auto overlayHUDTransparentsInputs = DrawOverlay3D::Inputs(overlaysHUDTransparent, lightingModel, nullJitter).asVarying(); task.addJob("DrawOverlayHUDOpaque", overlayHUDOpaquesInputs, true); task.addJob("DrawOverlayHUDTransparent", overlayHUDTransparentsInputs, false); - { // Debug the bounds of the rendered Overlay items that are marked drawHUDLayer, still look at the zbuffer - task.addJob("DrawOverlayHUDOpaqueBounds", overlaysHUDOpaque); - task.addJob("DrawOverlayHUDTransparentBounds", overlaysHUDTransparent); - } - task.addJob("ToneAndPostRangeTimer", toneAndPostRangeTimer); // Blit! @@ -413,13 +321,17 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input const auto& items = fetchCullSortTaskOut.get0(); const auto& spatialSelection = fetchCullSortTaskOut[1]; - // Extract opaques / transparents / lights / metas / overlays / background + // Extract opaques / transparents / lights / metas / overlays InFront and HUD / background const auto& opaques = items[RenderFetchCullSortTask::OPAQUE_SHAPE]; const auto& transparents = items[RenderFetchCullSortTask::TRANSPARENT_SHAPE]; const auto& lights = items[RenderFetchCullSortTask::LIGHT]; const auto& metas = items[RenderFetchCullSortTask::META]; const auto& overlayOpaques = items[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; const auto& overlayTransparents = items[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; + const auto& overlaysInFrontOpaque = items[RenderFetchCullSortTask::LAYER_FRONT_OPAQUE_SHAPE]; + const auto& overlaysInFrontTransparent = items[RenderFetchCullSortTask::LAYER_FRONT_TRANSPARENT_SHAPE]; + const auto& overlaysHUDOpaque = items[RenderFetchCullSortTask::LAYER_HUD_OPAQUE_SHAPE]; + const auto& overlaysHUDTransparent = items[RenderFetchCullSortTask::LAYER_HUD_TRANSPARENT_SHAPE]; // RenderShadowTask out const auto& renderShadowTaskOut = inputs[1]; @@ -446,6 +358,9 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input // Jitter out const auto& jitter = inputs[7]; + // Lighting Model out + const auto& lightingModel = inputs[8]; + { // Debug the bounds of the rendered items, still look at the zbuffer task.addJob("DrawMetaBounds", metas); @@ -476,14 +391,19 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input } { // Debug the bounds of the rendered Overlay items that are marked drawInFront, still look at the zbuffer - /* task.addJob("DrawOverlayInFrontOpaqueBounds", overlaysInFrontOpaque); + task.addJob("DrawOverlayInFrontOpaqueBounds", overlaysInFrontOpaque); task.addJob("DrawOverlayInFrontTransparentBounds", overlaysInFrontTransparent); - */ } + } + + { // Debug the bounds of the rendered Overlay items that are marked drawHUDLayer, still look at the zbuffer + task.addJob("DrawOverlayHUDOpaqueBounds", overlaysHUDOpaque); + task.addJob("DrawOverlayHUDTransparentBounds", overlaysHUDTransparent); + } // Debugging stages { // Debugging Deferred buffer job - /* const auto debugFramebuffers = render::Varying(DebugDeferredBuffer::Inputs(deferredFramebuffer, linearDepthTarget, surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, velocityBuffer, deferredFrameTransform, lightFrame)); + /* const auto debugFramebuffers = render::Varying(DebugDeferredBuffer::Inputs(deferredFramebuffer, linearDepthTarget, surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, velocityBuffer, deferredFrameTransform, lightFrame)); task.addJob("DebugDeferredBuffer", debugFramebuffers); const auto debugSubsurfaceScatteringInputs = DebugSubsurfaceScattering::Inputs(deferredFrameTransform, deferredFramebuffer, lightingModel, @@ -510,7 +430,10 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input const auto debugZoneInputs = DebugZoneLighting::Inputs(deferredFrameTransform, lightFrame, backgroundFrame).asVarying(); task.addJob("DrawZoneStack", debugZoneInputs); + } + + } diff --git a/libraries/task/src/task/Task.h b/libraries/task/src/task/Task.h index e8e95b4df4..87e7090d64 100644 --- a/libraries/task/src/task/Task.h +++ b/libraries/task/src/task/Task.h @@ -146,7 +146,7 @@ public: Concept(name, config), _data(Data(std::forward(args)...)), _input(input), - _output(Output()) { + _output(Output(), name + ".o") { applyConfiguration(); } diff --git a/libraries/task/src/task/Varying.h b/libraries/task/src/task/Varying.h index 2da0111bc2..6b076b0b27 100644 --- a/libraries/task/src/task/Varying.h +++ b/libraries/task/src/task/Varying.h @@ -27,12 +27,13 @@ public: _concept = var._concept; return (*this); } - template Varying(const T& data) : _concept(std::make_shared>(data)) {} + template Varying(const T& data, const std::string& name = "noname") : _concept(std::make_shared>(data, name)) {} template bool canCast() const { return !!std::dynamic_pointer_cast>(_concept); } template const T& get() const { return std::static_pointer_cast>(_concept)->_data; } template T& edit() { return std::static_pointer_cast>(_concept)->_data; } + const std::string& name() const { return _concept->name(); } // access potential sub varyings contained in this one. Varying operator[] (uint8_t index) const { return (*_concept)[index]; } @@ -46,16 +47,22 @@ public: protected: class Concept { public: + Concept(const std::string& name) : _name(name) {} + virtual ~Concept() = default; virtual Varying operator[] (uint8_t index) const = 0; virtual uint8_t length() const = 0; + + const std::string name() { return _name; } + + const std::string _name; }; template class Model : public Concept { public: using Data = T; - Model(const Data& data) : _data(data) {} + Model(const Data& data, const std::string& name) : Concept(name), _data(data) {} virtual ~Model() = default; virtual Varying operator[] (uint8_t index) const override { @@ -406,6 +413,29 @@ public: const T8& get8() const { return std::get<8>((*this)).template get(); } T8& edit8() { return std::get<8>((*this)).template edit(); } + virtual Varying operator[] (uint8_t index) const { + switch (index) { + default: + return std::get<0>((*this)); + case 1: + return std::get<1>((*this)); + case 2: + return std::get<2>((*this)); + case 3: + return std::get<3>((*this)); + case 4: + return std::get<4>((*this)); + case 5: + return std::get<5>((*this)); + case 6: + return std::get<6>((*this)); + case 7: + return std::get<7>((*this)); + case 8: + return std::get<8>((*this)); + }; + } + virtual uint8_t length() const { return 9; } Varying asVarying() const { return Varying((*this)); } }; From a5d1c4833e8236ca2e7b321801fb203200d25910 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 3 Dec 2018 00:00:28 -0800 Subject: [PATCH 07/31] Exploring varying with names --- libraries/task/src/task/Varying.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/libraries/task/src/task/Varying.h b/libraries/task/src/task/Varying.h index 6b076b0b27..7be49006b9 100644 --- a/libraries/task/src/task/Varying.h +++ b/libraries/task/src/task/Varying.h @@ -17,6 +17,15 @@ #include namespace task { +class Varying; + +template Varying varyingGetSub(const T& data, uint8_t index) { + return Varying(); +} + +template uint8_t varyingGetLength(const T& data) { + return 0; +} // A varying piece of data, to be used as Job/Task I/O class Varying { @@ -66,10 +75,11 @@ protected: virtual ~Model() = default; virtual Varying operator[] (uint8_t index) const override { - Varying var; - return var; + return varyingGetSub(_data, index); + } + virtual uint8_t length() const override { + return varyingGetLength(_data); } - virtual uint8_t length() const override { return 0; } Data _data; }; @@ -106,6 +116,12 @@ public: Varying asVarying() const { return Varying((*this)); } }; +template Varying varyingGetSub(const VaryingSet2& dat, uint8_t index) { + return data[index]; +} +template uint8_t varyingGetLength(const VaryingSet2& data) { + return data.length(); +} template class VaryingSet3 : public std::tuple{ From 0343983f31574d9c564776123bf83f38845fbf89 Mon Sep 17 00:00:00 2001 From: sam gateau Date: Mon, 3 Dec 2018 16:58:54 -0800 Subject: [PATCH 08/31] Applying changes done in deferred to forward --- .../render-utils/src/RenderForwardTask.cpp | 32 +++++++++++-------- scripts/developer/utilities/lib/jet/jet.js | 28 +++++++++++++++- .../utilities/lib/jet/qml/TaskList.qml | 2 +- 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/libraries/render-utils/src/RenderForwardTask.cpp b/libraries/render-utils/src/RenderForwardTask.cpp index 53f89aaec3..59461b3b44 100755 --- a/libraries/render-utils/src/RenderForwardTask.cpp +++ b/libraries/render-utils/src/RenderForwardTask.cpp @@ -48,7 +48,12 @@ using namespace render; extern void initForwardPipelines(ShapePlumber& plumber); void RenderForwardTask::build(JobModel& task, const render::Varying& input, render::Varying& output) { - auto items = input.get(); + // const auto& inputs = input.get(); + const auto& fetchedItems = input.get(); + // const auto& fetchedItems = inputs[0]; + // const auto& items = fetchedItems[0]; + const auto& items = fetchedItems.get0(); + auto fadeEffect = DependencyManager::get(); // Prepare the ShapePipelines @@ -56,15 +61,19 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend initForwardPipelines(*shapePlumber); // Extract opaques / transparents / lights / metas / overlays / background - const auto& opaques = items.get0()[RenderFetchCullSortTask::OPAQUE_SHAPE]; - const auto& transparents = items.get0()[RenderFetchCullSortTask::TRANSPARENT_SHAPE]; - //const auto& lights = items.get0()[RenderFetchCullSortTask::LIGHT]; - const auto& metas = items.get0()[RenderFetchCullSortTask::META]; - const auto& overlayOpaques = items.get0()[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; - const auto& overlayTransparents = items.get0()[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; + const auto& opaques = items[RenderFetchCullSortTask::OPAQUE_SHAPE]; + const auto& transparents = items[RenderFetchCullSortTask::TRANSPARENT_SHAPE]; + const auto& lights = items[RenderFetchCullSortTask::LIGHT]; + const auto& metas = items[RenderFetchCullSortTask::META]; + const auto& overlayOpaques = items[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; + const auto& overlayTransparents = items[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; + const auto& overlaysInFrontOpaque = items[RenderFetchCullSortTask::LAYER_FRONT_OPAQUE_SHAPE]; + const auto& overlaysInFrontTransparent = items[RenderFetchCullSortTask::LAYER_FRONT_TRANSPARENT_SHAPE]; + const auto& overlaysHUDOpaque = items[RenderFetchCullSortTask::LAYER_HUD_OPAQUE_SHAPE]; + const auto& overlaysHUDTransparent = items[RenderFetchCullSortTask::LAYER_HUD_TRANSPARENT_SHAPE]; + + const auto& spatialSelection = fetchedItems[1]; - //const auto& background = items.get0()[RenderFetchCullSortTask::BACKGROUND]; - //const auto& spatialSelection = items[1]; fadeEffect->build(task, opaques); @@ -91,12 +100,9 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend task.addJob("PrepareStencil", framebuffer); // Layered Overlays - const auto filteredOverlaysOpaque = task.addJob("FilterOverlaysLayeredOpaque", overlayOpaques, render::hifi::LAYER_3D_FRONT); - const auto filteredOverlaysTransparent = task.addJob("FilterOverlaysLayeredTransparent", overlayTransparents, render::hifi::LAYER_3D_FRONT); - const auto overlaysInFrontOpaque = filteredOverlaysOpaque.getN(0); - const auto overlaysInFrontTransparent = filteredOverlaysTransparent.getN(0); const auto nullJitter = Varying(glm::vec2(0.0f, 0.0f)); + // Layered Over (in front) const auto overlayInFrontOpaquesInputs = DrawOverlay3D::Inputs(overlaysInFrontOpaque, lightingModel, nullJitter).asVarying(); const auto overlayInFrontTransparentsInputs = DrawOverlay3D::Inputs(overlaysInFrontTransparent, lightingModel, nullJitter).asVarying(); task.addJob("DrawOverlayInFrontOpaque", overlayInFrontOpaquesInputs, true); diff --git a/scripts/developer/utilities/lib/jet/jet.js b/scripts/developer/utilities/lib/jet/jet.js index 85842b8861..d78b433a68 100644 --- a/scripts/developer/utilities/lib/jet/jet.js +++ b/scripts/developer/utilities/lib/jet/jet.js @@ -45,6 +45,24 @@ function job_propKeys(job) { return propKeys; } +// Access job inputs +// return all the inputs of a job +function job_inoutKeys(job) { + var keys = Object.keys(job) + var inoutKeys = []; + for (var k=0; k < keys.length;k++) { + // Filter for relevant property + var key = keys[k] + if ((typeof job[key]) !== "function") { + if ((key == "input") || (key == "output")) { + inoutKeys.push(keys[k]); + } + } + } + + return inoutKeys; +} + // Use this function to create a functor that will fill the specifed array with one entry name per task and job and it s rank function job_list_functor(jobList, maxDepth) { if (maxDepth === undefined) maxDepth = 100 @@ -55,7 +73,7 @@ function job_list_functor(jobList, maxDepth) { } // Use this function to create a functor that will print the content of the Job visited calling the specified 'printout' function -function job_print_functor(printout, showProps, maxDepth) { +function job_print_functor(printout, showProps, showInOuts, maxDepth) { if (maxDepth === undefined) maxDepth = 100 return function (job, depth, index) { var tab = " " @@ -69,6 +87,14 @@ function job_print_functor(printout, showProps, maxDepth) { printout(depthTab + tab + tab + typeof prop + " " + keys[p] + " " + prop); } } + if (showInOuts) { + printout("jsdkfkjdskflj") + var inouts = job_inoutKeys(job); + for (var p=0; p < inouts.length;p++) { + var prop = job[inouts[p]] + printout(depthTab + tab + tab + typeof prop + " " + inouts[p] + " " + prop); + } + } return depth < maxDepth; } } diff --git a/scripts/developer/utilities/lib/jet/qml/TaskList.qml b/scripts/developer/utilities/lib/jet/qml/TaskList.qml index 166f604666..e4b0267d3f 100644 --- a/scripts/developer/utilities/lib/jet/qml/TaskList.qml +++ b/scripts/developer/utilities/lib/jet/qml/TaskList.qml @@ -32,7 +32,7 @@ Rectangle { Component.onCompleted: { var message = "" - var functor = Jet.job_print_functor(function (line) { message += line + "\n"; }, false); + var functor = Jet.job_print_functor(function (line) { message += line + "\n"; }, false, true); Jet.task_traverseTree(rootConfig, functor); textArea.append(message); } From a267c3115a9f440e5981d4010f3c58394d70c8b9 Mon Sep 17 00:00:00 2001 From: sam gateau Date: Wed, 5 Dec 2018 17:47:33 -0800 Subject: [PATCH 09/31] drafting more factorisation of render tasks --- .../src/RenderableZoneEntityItem.cpp | 30 ------------------- libraries/render-utils/src/RenderCommonTask.h | 11 +++++++ .../render-utils/src/RenderDeferredTask.cpp | 4 +-- 3 files changed, 13 insertions(+), 32 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index 2c017da71d..95f390931b 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -74,36 +74,6 @@ void ZoneEntityRenderer::onRemoveFromSceneTyped(const TypedEntityPointer& entity } void ZoneEntityRenderer::doRender(RenderArgs* args) { -#if 0 - if (ZoneEntityItem::getDrawZoneBoundaries()) { - switch (_entity->getShapeType()) { - case SHAPE_TYPE_BOX: - case SHAPE_TYPE_SPHERE: - { - PerformanceTimer perfTimer("zone->renderPrimitive"); - static const glm::vec4 DEFAULT_COLOR(1.0f, 1.0f, 1.0f, 1.0f); - if (!updateModelTransform()) { - break; - } - auto geometryCache = DependencyManager::get(); - gpu::Batch& batch = *args->_batch; - batch.setModelTransform(_modelTransform); - if (_entity->getShapeType() == SHAPE_TYPE_SPHERE) { - geometryCache->renderWireSphereInstance(args, batch, DEFAULT_COLOR); - } else { - geometryCache->renderWireCubeInstance(args, batch, DEFAULT_COLOR); - } - } - break; - - // Compund shapes are handled by the _model member - case SHAPE_TYPE_COMPOUND: - default: - // Not handled - break; - } - } -#endif if (!_stage) { _stage = args->_scene->getStage(); assert(_stage); diff --git a/libraries/render-utils/src/RenderCommonTask.h b/libraries/render-utils/src/RenderCommonTask.h index 9b611bc38d..8f3a6e3ed4 100644 --- a/libraries/render-utils/src/RenderCommonTask.h +++ b/libraries/render-utils/src/RenderCommonTask.h @@ -129,4 +129,15 @@ public: void run(const render::RenderContextPointer& renderContext, Outputs& outputs); }; +class RenderUpdateStageLightingTask { +public: + using Inputs = + using Outputs = render::VaryingSet4; + using JobModel = render::Job::ModelIO; + + RenderUpdateStageLightingTask() {} + + void run(const render::RenderContextPointer& renderContext, Outputs& outputs); +}; + #endif // hifi_RenderDeferredTask_h diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index b6565b0c85..eab28ac0f6 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -207,7 +207,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto velocityBufferOutputs = task.addJob("VelocityBuffer", velocityBufferInputs); const auto velocityBuffer = velocityBufferOutputs.getN(0); - // Clear Light, Haze, Bloom, and Skybox Stages and render zones from the general metas bucket +/* // Clear Light, Haze, Bloom, and Skybox Stages and render zones from the general metas bucket const auto zones = task.addJob("ZoneRenderer", metas); // Draw Lights just add the lights to the current list of lights to deal with. NOt really gpu job for now. @@ -219,7 +219,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto backgroundFrame = currentStageFrames.getN(1); const auto hazeFrame = currentStageFrames.getN(2); const auto bloomFrame = currentStageFrames.getN(3); - +*/ // Light Clustering // Create the cluster grid of lights, cpu job for now const auto lightClusteringPassInputs = LightClusteringPass::Inputs(deferredFrameTransform, lightingModel, lightFrame, linearDepthTarget).asVarying(); From e941833676867778d77001bd82e266445a023c74 Mon Sep 17 00:00:00 2001 From: sam gateau Date: Thu, 6 Dec 2018 17:27:13 -0800 Subject: [PATCH 10/31] gathering the lighting stage jobs in their own task away from the renderer specificities --- .../src/AssembleLightingStageTask.cpp | 52 +++++++++++++++++++ .../src/AssembleLightingStageTask.h | 44 ++++++++++++++++ .../render-utils/src/RenderCommonTask.cpp | 17 ------ libraries/render-utils/src/RenderCommonTask.h | 29 +---------- .../render-utils/src/RenderDeferredTask.cpp | 26 +++++----- .../render-utils/src/RenderDeferredTask.h | 4 +- .../render-utils/src/RenderForwardTask.cpp | 24 ++++++--- .../render-utils/src/RenderForwardTask.h | 4 +- .../render-utils/src/RenderShadowTask.cpp | 1 + libraries/render-utils/src/RenderViewTask.cpp | 8 ++- libraries/task/src/task/Varying.h | 51 +++++++++++++++++- 11 files changed, 188 insertions(+), 72 deletions(-) create mode 100644 libraries/render-utils/src/AssembleLightingStageTask.cpp create mode 100644 libraries/render-utils/src/AssembleLightingStageTask.h diff --git a/libraries/render-utils/src/AssembleLightingStageTask.cpp b/libraries/render-utils/src/AssembleLightingStageTask.cpp new file mode 100644 index 0000000000..7ef5817edc --- /dev/null +++ b/libraries/render-utils/src/AssembleLightingStageTask.cpp @@ -0,0 +1,52 @@ +// +// Created by Samuel Gateau on 2018/12/06 +// Copyright 2013-2018 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#include "AssembleLightingStageTask.h" + + +void FetchCurrentFrames::run(const render::RenderContextPointer& renderContext, Outputs& outputs) { + auto lightStage = renderContext->_scene->getStage(); + assert(lightStage); + outputs.edit0() = std::make_shared(lightStage->_currentFrame); + + auto backgroundStage = renderContext->_scene->getStage(); + assert(backgroundStage); + outputs.edit1() = std::make_shared(backgroundStage->_currentFrame); + + auto hazeStage = renderContext->_scene->getStage(); + assert(hazeStage); + outputs.edit2() = std::make_shared(hazeStage->_currentFrame); + + auto bloomStage = renderContext->_scene->getStage(); + assert(bloomStage); + outputs.edit3() = std::make_shared(bloomStage->_currentFrame); +} + + +void RenderUpdateLightingStagesTask::build(JobModel& task, const render::Varying& input, render::Varying& output) { + const auto& items = input.get(); + + const auto& metas = items[RenderFetchCullSortTask::META]; + + // Clear Light, Haze, Bloom, and Skybox Stages and render zones from the general metas bucket + const auto zones = task.addJob("ZoneRenderer", metas); + + // Draw Lights just add the lights to the current list of lights to deal with. NOt really gpu job for now. + task.addJob("DrawLight", lights); + + // Fetch the current frame stacks from all the stages + const auto currentStageFrames = task.addJob("FetchCurrentFrames"); + + const auto lightFrame = currentStageFrames.getN(0); + const auto backgroundFrame = currentStageFrames.getN(1); + const auto hazeFrame = currentStageFrames.getN(2); + const auto bloomFrame = currentStageFrames.getN(3); + + outputs.edit0() = currentStageFrames; + outputs.edit1() = zones; +} + diff --git a/libraries/render-utils/src/AssembleLightingStageTask.h b/libraries/render-utils/src/AssembleLightingStageTask.h new file mode 100644 index 0000000000..bd440d23a1 --- /dev/null +++ b/libraries/render-utils/src/AssembleLightingStageTask.h @@ -0,0 +1,44 @@ +// +// Created by Samuel Gateau on 2018/12/06 +// Copyright 2013-2018 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_AssembleLightingStageTask_h +#define hifi_AssembleLightingStageTask_h + +#include +#include "LightingModel.h" + +#include "LightStage.h" +#include "BackgroundStage.h" +#include "HazeStage.h" +#include "BloomStage.h" + +#include "ZoneRenderer.h" + + +class FetchCurrentFrames { +public: + using Outputs = render::VaryingSet4; + using JobModel = render::Job::ModelO; + + FetchCurrentFrames() {} + + void run(const render::RenderContextPointer& renderContext, Outputs& outputs); +}; + +class AssembleLightingStageTask { +public: + using Inputs = RenderFetchCullSortTask::BucketList; + using Outputs = render::VaryingSet2; + using JobModel = render::Task::ModelIO; + + AssembleLightingStageTask() {} + + void build(JobModel& task, const render::Varying& input, render::Varying& output); +}; + +#endif diff --git a/libraries/render-utils/src/RenderCommonTask.cpp b/libraries/render-utils/src/RenderCommonTask.cpp index 4422d15d5c..863d6f19ea 100644 --- a/libraries/render-utils/src/RenderCommonTask.cpp +++ b/libraries/render-utils/src/RenderCommonTask.cpp @@ -232,20 +232,3 @@ void ExtractFrustums::run(const render::RenderContextPointer& renderContext, con } } -void FetchCurrentFrames::run(const render::RenderContextPointer& renderContext, Outputs& outputs) { - auto lightStage = renderContext->_scene->getStage(); - assert(lightStage); - outputs.edit0() = std::make_shared(lightStage->_currentFrame); - - auto backgroundStage = renderContext->_scene->getStage(); - assert(backgroundStage); - outputs.edit1() = std::make_shared(backgroundStage->_currentFrame); - - auto hazeStage = renderContext->_scene->getStage(); - assert(hazeStage); - outputs.edit2() = std::make_shared(hazeStage->_currentFrame); - - auto bloomStage = renderContext->_scene->getStage(); - assert(bloomStage); - outputs.edit3() = std::make_shared(bloomStage->_currentFrame); -} diff --git a/libraries/render-utils/src/RenderCommonTask.h b/libraries/render-utils/src/RenderCommonTask.h index 8f3a6e3ed4..5d4f2184a6 100644 --- a/libraries/render-utils/src/RenderCommonTask.h +++ b/libraries/render-utils/src/RenderCommonTask.h @@ -10,13 +10,8 @@ #define hifi_RenderCommonTask_h #include -#include -#include "LightingModel.h" - #include "LightStage.h" -#include "BackgroundStage.h" -#include "HazeStage.h" -#include "BloomStage.h" +#include "LightingModel.h" class BeginGPURangeTimer { public: @@ -118,26 +113,4 @@ public: void run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& output); }; - -class FetchCurrentFrames { -public: - using Outputs = render::VaryingSet4; - using JobModel = render::Job::ModelO; - - FetchCurrentFrames() {} - - void run(const render::RenderContextPointer& renderContext, Outputs& outputs); -}; - -class RenderUpdateStageLightingTask { -public: - using Inputs = - using Outputs = render::VaryingSet4; - using JobModel = render::Job::ModelIO; - - RenderUpdateStageLightingTask() {} - - void run(const render::RenderContextPointer& renderContext, Outputs& outputs); -}; - #endif // hifi_RenderDeferredTask_h diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index eab28ac0f6..62990cb819 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -151,6 +151,17 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto& spatialSelection = fetchedItems[1]; + // Extract the Lighting Stages Current frame ( and zones) + const auto& lightingStageInputs = inputs[1]; + // Fetch the current frame stacks from all the stages + const auto& currentStageFrames = lightingStageInputs[0]; + const auto& lightFrame = currentStageFrames[0]; + const auto& backgroundFrame = currentStageFrames[1]; + const auto& hazeFrame = currentStageFrames[2]; + const auto& bloomFrame = currentStageFrames[3]; + + const auto& zones = lightingStageInputs[1]; + fadeEffect->build(task, opaques); const auto jitter = task.addJob("JitterCam"); @@ -207,19 +218,6 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto velocityBufferOutputs = task.addJob("VelocityBuffer", velocityBufferInputs); const auto velocityBuffer = velocityBufferOutputs.getN(0); -/* // Clear Light, Haze, Bloom, and Skybox Stages and render zones from the general metas bucket - const auto zones = task.addJob("ZoneRenderer", metas); - - // Draw Lights just add the lights to the current list of lights to deal with. NOt really gpu job for now. - task.addJob("DrawLight", lights); - - // Fetch the current frame stacks from all the stages - const auto currentStageFrames = task.addJob("FetchCurrentFrames"); - const auto lightFrame = currentStageFrames.getN(0); - const auto backgroundFrame = currentStageFrames.getN(1); - const auto hazeFrame = currentStageFrames.getN(2); - const auto bloomFrame = currentStageFrames.getN(3); -*/ // Light Clustering // Create the cluster grid of lights, cpu job for now const auto lightClusteringPassInputs = LightClusteringPass::Inputs(deferredFrameTransform, lightingModel, lightFrame, linearDepthTarget).asVarying(); @@ -279,7 +277,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren // Debugging task is happening in the "over" layer after tone mapping and just before HUD { // Debug the bounds of the rendered items, still look at the zbuffer - const auto debugInputs = RenderDeferredTaskDebug::Input(fetchedItems, inputs[1], zones, selectedItems, currentStageFrames, prepareDeferredOutputs, deferredFrameTransform, jitter, lightingModel).asVarying(); + const auto debugInputs = RenderDeferredTaskDebug::Input(fetchedItems, inputs[2], zones, selectedItems, currentStageFrames, prepareDeferredOutputs, deferredFrameTransform, jitter, lightingModel).asVarying(); task.addJob("DebugRenderDeferredTask", debugInputs); } diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index c18daa6d3d..078b792d57 100644 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -14,10 +14,10 @@ #include #include +#include "AssembleLightingStageTask.h" #include "LightingModel.h" #include "LightClusters.h" #include "RenderShadowTask.h" -#include "HazeStage.h" class DrawDeferredConfig : public render::Job::Config { Q_OBJECT @@ -137,7 +137,7 @@ signals: class RenderDeferredTask { public: - using Input = render::VaryingSet2; + using Input = render::VaryingSet3; using Config = RenderDeferredTaskConfig; using JobModel = render::Task::ModelI; diff --git a/libraries/render-utils/src/RenderForwardTask.cpp b/libraries/render-utils/src/RenderForwardTask.cpp index 59461b3b44..fb29f026e2 100755 --- a/libraries/render-utils/src/RenderForwardTask.cpp +++ b/libraries/render-utils/src/RenderForwardTask.cpp @@ -48,12 +48,24 @@ using namespace render; extern void initForwardPipelines(ShapePlumber& plumber); void RenderForwardTask::build(JobModel& task, const render::Varying& input, render::Varying& output) { - // const auto& inputs = input.get(); - const auto& fetchedItems = input.get(); + const auto& inputs = input.get(); + const auto& fetchedItems = inputs.get0(); // const auto& fetchedItems = inputs[0]; // const auto& items = fetchedItems[0]; const auto& items = fetchedItems.get0(); + + const auto& lightingStageInputs = inputs[1]; + // Fetch the current frame stacks from all the stages + const auto& currentStageFrames = lightingStageInputs[0]; + const auto& lightFrame = currentStageFrames[0]; + const auto& backgroundFrame = currentStageFrames[1]; + const auto& hazeFrame = currentStageFrames[2]; + const auto& bloomFrame = currentStageFrames[3]; + + const auto& zones = lightingStageInputs[1]; + + auto fadeEffect = DependencyManager::get(); // Prepare the ShapePipelines @@ -82,12 +94,12 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend const auto lightingModel = task.addJob("LightingModel"); // Filter zones from the general metas bucket - const auto zones = task.addJob("ZoneRenderer", metas); + // const auto zones = task.addJob("ZoneRenderer", metas); // Fetch the current frame stacks from all the stages - const auto currentFrames = task.addJob("FetchCurrentFrames"); - const auto lightFrame = currentFrames.getN(0); - const auto backgroundFrame = currentFrames.getN(1); + // const auto currentFrames = task.addJob("FetchCurrentFrames"); + // const auto lightFrame = currentFrames.getN(0); + // const auto backgroundFrame = currentFrames.getN(1); //const auto hazeFrame = currentFrames.getN(2); //const auto bloomFrame = currentFrames.getN(3); diff --git a/libraries/render-utils/src/RenderForwardTask.h b/libraries/render-utils/src/RenderForwardTask.h index 54341d1ded..0a2684555d 100755 --- a/libraries/render-utils/src/RenderForwardTask.h +++ b/libraries/render-utils/src/RenderForwardTask.h @@ -14,12 +14,12 @@ #include #include +#include "AssembleLightingStageTask.h" #include "LightingModel.h" -#include "LightStage.h" class RenderForwardTask { public: - using Input = RenderFetchCullSortTask::Output; + using Input = render::VaryingSet2; using JobModel = render::Task::ModelI; RenderForwardTask() {} diff --git a/libraries/render-utils/src/RenderShadowTask.cpp b/libraries/render-utils/src/RenderShadowTask.cpp index b5b3e9c5b9..a753722489 100644 --- a/libraries/render-utils/src/RenderShadowTask.cpp +++ b/libraries/render-utils/src/RenderShadowTask.cpp @@ -25,6 +25,7 @@ #include "RenderUtilsLogging.h" #include "RenderCommonTask.h" +#include "AssembleLightingStageTask.h" #include "FadeEffect.h" diff --git a/libraries/render-utils/src/RenderViewTask.cpp b/libraries/render-utils/src/RenderViewTask.cpp index 2e03082ff4..53e50d244e 100644 --- a/libraries/render-utils/src/RenderViewTask.cpp +++ b/libraries/render-utils/src/RenderViewTask.cpp @@ -10,6 +10,7 @@ // #include "RenderViewTask.h" +#include "AssembleLightingStageTask.h" #include "RenderShadowTask.h" #include "RenderDeferredTask.h" #include "RenderForwardTask.h" @@ -20,14 +21,17 @@ void RenderViewTask::build(JobModel& task, const render::Varying& input, render: const auto items = task.addJob("FetchCullSort", cullFunctor, tagBits, tagMask); assert(items.canCast()); + + const auto lightingStageFramesAndZones = task.addJob("AssembleStages", items[0]); + if (isDeferred) { // Warning : the cull functor passed to the shadow pass should only be testing for LOD culling. If frustum culling // is performed, then casters not in the view frustum will be removed, which is not what we wish. const auto cascadeSceneBBoxes = task.addJob("RenderShadowTask", cullFunctor, tagBits, tagMask); - const auto renderInput = RenderDeferredTask::Input(items, cascadeSceneBBoxes).asVarying(); + const auto renderInput = RenderDeferredTask::Input(items, lightingStageFramesAndZones, cascadeSceneBBoxes).asVarying(); task.addJob("RenderDeferredTask", renderInput, true); } else { - task.addJob("Forward", items); + task.addJob("Forward", items, lightingStageFramesAndZones); } } diff --git a/libraries/task/src/task/Varying.h b/libraries/task/src/task/Varying.h index 7be49006b9..10c894c72f 100644 --- a/libraries/task/src/task/Varying.h +++ b/libraries/task/src/task/Varying.h @@ -155,6 +155,13 @@ public: Varying asVarying() const { return Varying((*this)); } }; +template Varying varyingGetSub(const VaryingSet3& dat, uint8_t index) { + return data[index]; +} +template uint8_t varyingGetLength(const VaryingSet3& data) { + return data.length(); +} + template class VaryingSet4 : public std::tuple{ public: @@ -191,7 +198,12 @@ public: Varying asVarying() const { return Varying((*this)); } }; - +template Varying varyingGetSub(const VaryingSet4& dat, uint8_t index) { + return data[index]; +} +template uint8_t varyingGetLength(const VaryingSet4& data) { + return data.length(); +} template class VaryingSet5 : public std::tuple{ @@ -234,6 +246,12 @@ public: Varying asVarying() const { return Varying((*this)); } }; +template Varying varyingGetSub(const VaryingSet5& dat, uint8_t index) { + return data[index]; +} +template uint8_t varyingGetLength(const VaryingSet5& data) { + return data.length(); +} template class VaryingSet6 : public std::tuple{ @@ -282,6 +300,12 @@ public: Varying asVarying() const { return Varying((*this)); } }; +template Varying varyingGetSub(const VaryingSet6& dat, uint8_t index) { + return data[index]; +} +template uint8_t varyingGetLength(const VaryingSet6& data) { + return data.length(); +} template class VaryingSet7 : public std::tuple{ @@ -335,6 +359,12 @@ public: Varying asVarying() const { return Varying((*this)); } }; +template Varying varyingGetSub(const VaryingSet7& dat, uint8_t index) { + return data[index]; +} +template uint8_t varyingGetLength(const VaryingSet7& data) { + return data.length(); +} template class VaryingSet8 : public std::tuple { @@ -393,6 +423,12 @@ public: Varying asVarying() const { return Varying((*this)); } }; +template Varying varyingGetSub(const VaryingSet8& dat, uint8_t index) { + return data[index]; +} +template uint8_t varyingGetLength(const VaryingSet8& data) { + return data.length(); +} template class VaryingSet9 : public std::tuple { @@ -455,6 +491,12 @@ public: Varying asVarying() const { return Varying((*this)); } }; +template Varying varyingGetSub(const VaryingSet9& dat, uint8_t index) { + return data[index]; +} +template uint8_t varyingGetLength(const VaryingSet9& data) { + return data.length(); +} template < class T, int NUM > class VaryingArray : public std::array { @@ -470,6 +512,13 @@ public: std::copy(list.begin(), list.end(), std::array::begin()); } }; +template Varying varyingGetSub(const VaryingArray& dat, uint8_t index) { + return data[index]; +} +template uint8_t varyingGetLength(const VaryingArray& data) { + return NUM; +} + } #endif // hifi_task_Varying_h From 50fcd7f40a4937dc41b780e0e5862a0a78f95e48 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Thu, 6 Dec 2018 22:45:44 -0800 Subject: [PATCH 11/31] trying... --- interface/src/SecondaryCamera.cpp | 9 +++++-- .../src/gpu/gl/GLBackendTransform.cpp | 6 ++--- .../src/AssembleLightingStageTask.cpp | 27 ++++++++++--------- .../src/AssembleLightingStageTask.h | 13 ++++----- .../render-utils/src/RenderDeferredTask.cpp | 11 ++++---- .../render-utils/src/RenderDeferredTask.h | 4 +-- .../render-utils/src/RenderForwardTask.h | 4 +-- .../render-utils/src/RenderShadowTask.cpp | 2 +- libraries/render-utils/src/RenderViewTask.cpp | 7 ++--- libraries/render-utils/src/ZoneRenderer.cpp | 4 +-- libraries/render-utils/src/ZoneRenderer.h | 14 +++++----- 11 files changed, 56 insertions(+), 45 deletions(-) diff --git a/interface/src/SecondaryCamera.cpp b/interface/src/SecondaryCamera.cpp index e71602b271..102f94b63d 100644 --- a/interface/src/SecondaryCamera.cpp +++ b/interface/src/SecondaryCamera.cpp @@ -206,12 +206,17 @@ void SecondaryCameraRenderTask::build(JobModel& task, const render::Varying& inp const auto cachedArg = task.addJob("SecondaryCamera"); const auto items = task.addJob("FetchCullSort", cullFunctor, render::ItemKey::TAG_BITS_1, render::ItemKey::TAG_BITS_1); assert(items.canCast()); + + // const auto lightingStageFramesAndZones = task.addJob("AssembleStages", items[0]); + const auto lightingStageFramesAndZones = task.addJob("AssembleStages", items); + if (isDeferred) { const render::Varying cascadeSceneBBoxes; - const auto renderInput = RenderDeferredTask::Input(items, cascadeSceneBBoxes).asVarying(); + const auto renderInput = RenderDeferredTask::Input(items, lightingStageFramesAndZones, cascadeSceneBBoxes).asVarying(); task.addJob("RenderDeferredTask", renderInput, false); } else { - task.addJob("Forward", items); + const auto renderInput = RenderForwardTask::Input(items, lightingStageFramesAndZones).asVarying(); + task.addJob("Forward", renderInput); } task.addJob("EndSecondaryCamera", cachedArg); } \ No newline at end of file diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLBackendTransform.cpp b/libraries/gpu-gl-common/src/gpu/gl/GLBackendTransform.cpp index 2c2a4e254c..555a0a1e41 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLBackendTransform.cpp +++ b/libraries/gpu-gl-common/src/gpu/gl/GLBackendTransform.cpp @@ -29,9 +29,9 @@ void GLBackend::do_setProjectionTransform(const Batch& batch, size_t paramOffset } void GLBackend::do_setProjectionJitter(const Batch& batch, size_t paramOffset) { - _transform._projectionJitter.x = batch._params[paramOffset]._float; - _transform._projectionJitter.y = batch._params[paramOffset+1]._float; - _transform._invalidProj = true; + _transform._projectionJitter.x = batch._params[paramOffset]._float; + _transform._projectionJitter.y = batch._params[paramOffset+1]._float; + _transform._invalidProj = true; } void GLBackend::do_setViewportTransform(const Batch& batch, size_t paramOffset) { diff --git a/libraries/render-utils/src/AssembleLightingStageTask.cpp b/libraries/render-utils/src/AssembleLightingStageTask.cpp index 7ef5817edc..beb9f226d6 100644 --- a/libraries/render-utils/src/AssembleLightingStageTask.cpp +++ b/libraries/render-utils/src/AssembleLightingStageTask.cpp @@ -7,46 +7,49 @@ // #include "AssembleLightingStageTask.h" +#include -void FetchCurrentFrames::run(const render::RenderContextPointer& renderContext, Outputs& outputs) { +void FetchCurrentFrames::run(const render::RenderContextPointer& renderContext, Output& output) { auto lightStage = renderContext->_scene->getStage(); assert(lightStage); - outputs.edit0() = std::make_shared(lightStage->_currentFrame); + output.edit0() = std::make_shared(lightStage->_currentFrame); auto backgroundStage = renderContext->_scene->getStage(); assert(backgroundStage); - outputs.edit1() = std::make_shared(backgroundStage->_currentFrame); + output.edit1() = std::make_shared(backgroundStage->_currentFrame); auto hazeStage = renderContext->_scene->getStage(); assert(hazeStage); - outputs.edit2() = std::make_shared(hazeStage->_currentFrame); + output.edit2() = std::make_shared(hazeStage->_currentFrame); auto bloomStage = renderContext->_scene->getStage(); assert(bloomStage); - outputs.edit3() = std::make_shared(bloomStage->_currentFrame); + output.edit3() = std::make_shared(bloomStage->_currentFrame); } -void RenderUpdateLightingStagesTask::build(JobModel& task, const render::Varying& input, render::Varying& output) { - const auto& items = input.get(); +void AssembleLightingStageTask::build(JobModel& task, const render::Varying& input, render::Varying& output) { + const auto& fetchCullSortOut = input.get(); + const auto& items = fetchCullSortOut[0]; + //const auto& items = input.get(); + const auto& lights = items[RenderFetchCullSortTask::LIGHT]; const auto& metas = items[RenderFetchCullSortTask::META]; // Clear Light, Haze, Bloom, and Skybox Stages and render zones from the general metas bucket const auto zones = task.addJob("ZoneRenderer", metas); // Draw Lights just add the lights to the current list of lights to deal with. NOt really gpu job for now. - task.addJob("DrawLight", lights); + task.addJob("DrawLight", lights); // Fetch the current frame stacks from all the stages const auto currentStageFrames = task.addJob("FetchCurrentFrames"); - const auto lightFrame = currentStageFrames.getN(0); + /* const auto lightFrame = currentStageFrames.getN(0); const auto backgroundFrame = currentStageFrames.getN(1); const auto hazeFrame = currentStageFrames.getN(2); const auto bloomFrame = currentStageFrames.getN(3); - - outputs.edit0() = currentStageFrames; - outputs.edit1() = zones; +*/ + output = Output(currentStageFrames, zones); } diff --git a/libraries/render-utils/src/AssembleLightingStageTask.h b/libraries/render-utils/src/AssembleLightingStageTask.h index bd440d23a1..c32d5f9a30 100644 --- a/libraries/render-utils/src/AssembleLightingStageTask.h +++ b/libraries/render-utils/src/AssembleLightingStageTask.h @@ -22,19 +22,20 @@ class FetchCurrentFrames { public: - using Outputs = render::VaryingSet4; - using JobModel = render::Job::ModelO; + using Output = render::VaryingSet4; + using JobModel = render::Job::ModelO; FetchCurrentFrames() {} - void run(const render::RenderContextPointer& renderContext, Outputs& outputs); + void run(const render::RenderContextPointer& renderContext, Output& output); }; class AssembleLightingStageTask { public: - using Inputs = RenderFetchCullSortTask::BucketList; - using Outputs = render::VaryingSet2; - using JobModel = render::Task::ModelIO; + // using Input = RenderFetchCullSortTask::BucketList; + using Input = RenderFetchCullSortTask::Output; + using Output = render::VaryingSet2; + using JobModel = render::Task::ModelIO; AssembleLightingStageTask() {} diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 62990cb819..c1b72c9ca6 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -84,7 +84,7 @@ public: class RenderDeferredTaskDebug { public: using Input = render::VaryingSet9; // using Config = RenderDeferredTaskConfig; using JobModel = render::Task::ModelI; @@ -152,11 +152,12 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto& spatialSelection = fetchedItems[1]; // Extract the Lighting Stages Current frame ( and zones) - const auto& lightingStageInputs = inputs[1]; + //const auto lightingStageInputs = inputs[1]; + const auto lightingStageInputs = input[1]; // Fetch the current frame stacks from all the stages - const auto& currentStageFrames = lightingStageInputs[0]; - const auto& lightFrame = currentStageFrames[0]; - const auto& backgroundFrame = currentStageFrames[1]; + const auto currentStageFrames = lightingStageInputs[0]; + const auto lightFrame = currentStageFrames[0]; + const auto backgroundFrame = currentStageFrames[1]; const auto& hazeFrame = currentStageFrames[2]; const auto& bloomFrame = currentStageFrames[3]; diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index 078b792d57..81f158918c 100644 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -137,14 +137,14 @@ signals: class RenderDeferredTask { public: - using Input = render::VaryingSet3; + using Input = render::VaryingSet3; using Config = RenderDeferredTaskConfig; using JobModel = render::Task::ModelI; RenderDeferredTask(); void configure(const Config& config); - void build(JobModel& task, const render::Varying& inputs, render::Varying& outputs, bool renderShadows); + void build(JobModel& task, const render::Varying& input, render::Varying& output, bool renderShadows); private: static const render::Varying addSelectItemJobs(JobModel& task, diff --git a/libraries/render-utils/src/RenderForwardTask.h b/libraries/render-utils/src/RenderForwardTask.h index 0a2684555d..60d3dbd54d 100755 --- a/libraries/render-utils/src/RenderForwardTask.h +++ b/libraries/render-utils/src/RenderForwardTask.h @@ -19,12 +19,12 @@ class RenderForwardTask { public: - using Input = render::VaryingSet2; + using Input = render::VaryingSet2; using JobModel = render::Task::ModelI; RenderForwardTask() {} - void build(JobModel& task, const render::Varying& inputs, render::Varying& outputs); + void build(JobModel& task, const render::Varying& input, render::Varying& output); }; class PrepareFramebuffer { diff --git a/libraries/render-utils/src/RenderShadowTask.cpp b/libraries/render-utils/src/RenderShadowTask.cpp index a753722489..2232deb3d6 100644 --- a/libraries/render-utils/src/RenderShadowTask.cpp +++ b/libraries/render-utils/src/RenderShadowTask.cpp @@ -59,7 +59,7 @@ void RenderShadowTask::build(JobModel& task, const render::Varying& input, rende // FIXME: calling this here before the zones/lights are drawn during the deferred/forward passes means we're actually using the frames from the previous draw // Fetch the current frame stacks from all the stages const auto currentFrames = task.addJob("FetchCurrentFrames"); - const auto lightFrame = currentFrames.getN(0); + const auto lightFrame = currentFrames.getN(0); const auto setupOutput = task.addJob("ShadowSetup", lightFrame); const auto queryResolution = setupOutput.getN(1); diff --git a/libraries/render-utils/src/RenderViewTask.cpp b/libraries/render-utils/src/RenderViewTask.cpp index 53e50d244e..d9ba4e1a56 100644 --- a/libraries/render-utils/src/RenderViewTask.cpp +++ b/libraries/render-utils/src/RenderViewTask.cpp @@ -21,8 +21,8 @@ void RenderViewTask::build(JobModel& task, const render::Varying& input, render: const auto items = task.addJob("FetchCullSort", cullFunctor, tagBits, tagMask); assert(items.canCast()); - - const auto lightingStageFramesAndZones = task.addJob("AssembleStages", items[0]); + // const auto lightingStageFramesAndZones = task.addJob("AssembleStages", items[0]); + const auto lightingStageFramesAndZones = task.addJob("AssembleStages", items); if (isDeferred) { // Warning : the cull functor passed to the shadow pass should only be testing for LOD culling. If frustum culling @@ -31,7 +31,8 @@ void RenderViewTask::build(JobModel& task, const render::Varying& input, render: const auto renderInput = RenderDeferredTask::Input(items, lightingStageFramesAndZones, cascadeSceneBBoxes).asVarying(); task.addJob("RenderDeferredTask", renderInput, true); } else { - task.addJob("Forward", items, lightingStageFramesAndZones); + const auto renderInput = RenderForwardTask::Input(items, lightingStageFramesAndZones).asVarying(); + task.addJob("Forward", renderInput); } } diff --git a/libraries/render-utils/src/ZoneRenderer.cpp b/libraries/render-utils/src/ZoneRenderer.cpp index 4ffc8730a7..0e9672a7f2 100644 --- a/libraries/render-utils/src/ZoneRenderer.cpp +++ b/libraries/render-utils/src/ZoneRenderer.cpp @@ -51,7 +51,7 @@ void ZoneRendererTask::build(JobModel& task, const Varying& input, Varying& outp output = zoneItems; } -void SetupZones::run(const RenderContextPointer& context, const Inputs& inputs) { +void SetupZones::run(const RenderContextPointer& context, const Input& input) { // Grab light, background, haze, and bloom stages and clear them auto lightStage = context->_scene->getStage(); assert(lightStage); @@ -70,7 +70,7 @@ void SetupZones::run(const RenderContextPointer& context, const Inputs& inputs) bloomStage->_currentFrame.clear(); // call render over the zones to grab their components in the correct order first... - render::renderItems(context, inputs); + render::renderItems(context, input); // Finally add the default lights and background: lightStage->_currentFrame.pushSunLight(lightStage->getDefaultLight()); diff --git a/libraries/render-utils/src/ZoneRenderer.h b/libraries/render-utils/src/ZoneRenderer.h index 36d63a98d1..6eeee1293a 100644 --- a/libraries/render-utils/src/ZoneRenderer.h +++ b/libraries/render-utils/src/ZoneRenderer.h @@ -21,12 +21,12 @@ class SetupZones { public: - using Inputs = render::ItemBounds; - using JobModel = render::Job::ModelI; + using Input = render::ItemBounds; + using JobModel = render::Job::ModelI; SetupZones() {} - void run(const render::RenderContextPointer& context, const Inputs& inputs); + void run(const render::RenderContextPointer& context, const Input& input); }; class ZoneRendererConfig : public render::Task::Config { @@ -51,14 +51,14 @@ public: static const render::Selection::Name ZONES_SELECTION; - using Inputs = render::ItemBounds; - using Outputs = render::ItemBounds; + using Input = render::ItemBounds; + using Output = render::ItemBounds; using Config = ZoneRendererConfig; - using JobModel = render::Task::ModelIO; + using JobModel = render::Task::ModelIO; ZoneRendererTask() {} - void build(JobModel& task, const render::Varying& inputs, render::Varying& output); + void build(JobModel& task, const render::Varying& input, render::Varying& output); void configure(const Config& config) { _maxDrawn = config.maxDrawn; } From 28d36c81e0ed774e3da9a7be0dcc2e9b09fc9c39 Mon Sep 17 00:00:00 2001 From: sam gateau Date: Fri, 7 Dec 2018 16:24:51 -0800 Subject: [PATCH 12/31] there and back , trying to converge with the new Assemble Lighting Stage task --- .../render-utils/src/RenderDeferredTask.cpp | 5 +- .../render-utils/src/RenderForwardTask.cpp | 4 +- libraries/task/src/task/Task.cpp | 2 - libraries/task/src/task/Varying.h | 72 ++----------------- 4 files changed, 8 insertions(+), 75 deletions(-) diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index c1b72c9ca6..223efbeba4 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -152,10 +152,9 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto& spatialSelection = fetchedItems[1]; // Extract the Lighting Stages Current frame ( and zones) - //const auto lightingStageInputs = inputs[1]; - const auto lightingStageInputs = input[1]; + const auto lightingStageInputs = inputs.get1(); // Fetch the current frame stacks from all the stages - const auto currentStageFrames = lightingStageInputs[0]; + const auto currentStageFrames = lightingStageInputs.get0(); const auto lightFrame = currentStageFrames[0]; const auto backgroundFrame = currentStageFrames[1]; const auto& hazeFrame = currentStageFrames[2]; diff --git a/libraries/render-utils/src/RenderForwardTask.cpp b/libraries/render-utils/src/RenderForwardTask.cpp index fb29f026e2..31e22f00d5 100755 --- a/libraries/render-utils/src/RenderForwardTask.cpp +++ b/libraries/render-utils/src/RenderForwardTask.cpp @@ -55,9 +55,9 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend const auto& items = fetchedItems.get0(); - const auto& lightingStageInputs = inputs[1]; + const auto& lightingStageInputs = inputs.get1(); // Fetch the current frame stacks from all the stages - const auto& currentStageFrames = lightingStageInputs[0]; + const auto& currentStageFrames = lightingStageInputs.get0(); const auto& lightFrame = currentStageFrames[0]; const auto& backgroundFrame = currentStageFrames[1]; const auto& hazeFrame = currentStageFrames[2]; diff --git a/libraries/task/src/task/Task.cpp b/libraries/task/src/task/Task.cpp index 9123ef8b04..2d6493fbc5 100644 --- a/libraries/task/src/task/Task.cpp +++ b/libraries/task/src/task/Task.cpp @@ -29,5 +29,3 @@ void TaskFlow::abortTask() { bool TaskFlow::doAbortTask() const { return _doAbortTask; } - - diff --git a/libraries/task/src/task/Varying.h b/libraries/task/src/task/Varying.h index 10c894c72f..c81d8b6753 100644 --- a/libraries/task/src/task/Varying.h +++ b/libraries/task/src/task/Varying.h @@ -19,13 +19,6 @@ namespace task { class Varying; -template Varying varyingGetSub(const T& data, uint8_t index) { - return Varying(); -} - -template uint8_t varyingGetLength(const T& data) { - return 0; -} // A varying piece of data, to be used as Job/Task I/O class Varying { @@ -75,10 +68,10 @@ protected: virtual ~Model() = default; virtual Varying operator[] (uint8_t index) const override { - return varyingGetSub(_data, index); + return Varying(); } virtual uint8_t length() const override { - return varyingGetLength(_data); + return 0; } Data _data; @@ -87,11 +80,10 @@ protected: std::shared_ptr _concept; }; -using VaryingPairBase = std::pair; template < typename T0, typename T1 > -class VaryingSet2 : public VaryingPairBase { +class VaryingSet2 : public std::pair { public: - using Parent = VaryingPairBase; + using Parent = std::pair; typedef void is_proxy_tag; VaryingSet2() : Parent(Varying(T0()), Varying(T1())) {} @@ -116,13 +108,6 @@ public: Varying asVarying() const { return Varying((*this)); } }; -template Varying varyingGetSub(const VaryingSet2& dat, uint8_t index) { - return data[index]; -} -template uint8_t varyingGetLength(const VaryingSet2& data) { - return data.length(); -} - template class VaryingSet3 : public std::tuple{ public: @@ -155,13 +140,6 @@ public: Varying asVarying() const { return Varying((*this)); } }; -template Varying varyingGetSub(const VaryingSet3& dat, uint8_t index) { - return data[index]; -} -template uint8_t varyingGetLength(const VaryingSet3& data) { - return data.length(); -} - template class VaryingSet4 : public std::tuple{ public: @@ -198,12 +176,6 @@ public: Varying asVarying() const { return Varying((*this)); } }; -template Varying varyingGetSub(const VaryingSet4& dat, uint8_t index) { - return data[index]; -} -template uint8_t varyingGetLength(const VaryingSet4& data) { - return data.length(); -} template class VaryingSet5 : public std::tuple{ @@ -246,12 +218,6 @@ public: Varying asVarying() const { return Varying((*this)); } }; -template Varying varyingGetSub(const VaryingSet5& dat, uint8_t index) { - return data[index]; -} -template uint8_t varyingGetLength(const VaryingSet5& data) { - return data.length(); -} template class VaryingSet6 : public std::tuple{ @@ -300,12 +266,6 @@ public: Varying asVarying() const { return Varying((*this)); } }; -template Varying varyingGetSub(const VaryingSet6& dat, uint8_t index) { - return data[index]; -} -template uint8_t varyingGetLength(const VaryingSet6& data) { - return data.length(); -} template class VaryingSet7 : public std::tuple{ @@ -359,12 +319,6 @@ public: Varying asVarying() const { return Varying((*this)); } }; -template Varying varyingGetSub(const VaryingSet7& dat, uint8_t index) { - return data[index]; -} -template uint8_t varyingGetLength(const VaryingSet7& data) { - return data.length(); -} template class VaryingSet8 : public std::tuple { @@ -423,12 +377,6 @@ public: Varying asVarying() const { return Varying((*this)); } }; -template Varying varyingGetSub(const VaryingSet8& dat, uint8_t index) { - return data[index]; -} -template uint8_t varyingGetLength(const VaryingSet8& data) { - return data.length(); -} template class VaryingSet9 : public std::tuple { @@ -491,12 +439,6 @@ public: Varying asVarying() const { return Varying((*this)); } }; -template Varying varyingGetSub(const VaryingSet9& dat, uint8_t index) { - return data[index]; -} -template uint8_t varyingGetLength(const VaryingSet9& data) { - return data.length(); -} template < class T, int NUM > class VaryingArray : public std::array { @@ -512,12 +454,6 @@ public: std::copy(list.begin(), list.end(), std::array::begin()); } }; -template Varying varyingGetSub(const VaryingArray& dat, uint8_t index) { - return data[index]; -} -template uint8_t varyingGetLength(const VaryingArray& data) { - return NUM; -} } From 653370e2842547d63d2f075dd32e0a7d789abc33 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Sun, 9 Dec 2018 11:39:35 -0800 Subject: [PATCH 13/31] Assemble lighting stage works --- libraries/render-utils/src/AssembleLightingStageTask.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render-utils/src/AssembleLightingStageTask.cpp b/libraries/render-utils/src/AssembleLightingStageTask.cpp index beb9f226d6..ff9eaa195e 100644 --- a/libraries/render-utils/src/AssembleLightingStageTask.cpp +++ b/libraries/render-utils/src/AssembleLightingStageTask.cpp @@ -30,7 +30,7 @@ void FetchCurrentFrames::run(const render::RenderContextPointer& renderContext, void AssembleLightingStageTask::build(JobModel& task, const render::Varying& input, render::Varying& output) { const auto& fetchCullSortOut = input.get(); - const auto& items = fetchCullSortOut[0]; + const auto& items = fetchCullSortOut.get0(); //const auto& items = input.get(); const auto& lights = items[RenderFetchCullSortTask::LIGHT]; From b09d0b10e90f1ceaa33a399bbbdd6f4bc436b492 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Sun, 9 Dec 2018 22:54:49 -0800 Subject: [PATCH 14/31] cleaning light clusters --- libraries/render-utils/src/LightClusters.cpp | 9 +-- libraries/render-utils/src/LightClusters.h | 10 +-- .../render-utils/src/RenderDeferredTask.cpp | 76 ++++++++++--------- .../render-utils/src/RenderDeferredTask.h | 5 -- 4 files changed, 48 insertions(+), 52 deletions(-) diff --git a/libraries/render-utils/src/LightClusters.cpp b/libraries/render-utils/src/LightClusters.cpp index 252416ea9d..3dc826d56c 100644 --- a/libraries/render-utils/src/LightClusters.cpp +++ b/libraries/render-utils/src/LightClusters.cpp @@ -543,7 +543,7 @@ void LightClusteringPass::configure(const Config& config) { _freeze = config.freeze; } -void LightClusteringPass::run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& output) { +void LightClusteringPass::run(const render::RenderContextPointer& renderContext, const Input& inputs, Output& output) { auto args = renderContext->args; auto deferredTransform = inputs.get0(); @@ -638,10 +638,9 @@ void DebugLightClusters::run(const render::RenderContextPointer& renderContext, } auto deferredTransform = inputs.get0(); - auto deferredFramebuffer = inputs.get1(); - auto lightingModel = inputs.get2(); - auto linearDepthTarget = inputs.get3(); - auto lightClusters = inputs.get4(); + auto lightingModel = inputs.get1(); + auto linearDepthTarget = inputs.get2(); + auto lightClusters = inputs.get3(); auto args = renderContext->args; diff --git a/libraries/render-utils/src/LightClusters.h b/libraries/render-utils/src/LightClusters.h index e109e43aaa..60978e76e8 100644 --- a/libraries/render-utils/src/LightClusters.h +++ b/libraries/render-utils/src/LightClusters.h @@ -167,16 +167,16 @@ protected: class LightClusteringPass { public: - using Inputs = render::VaryingSet4; - using Outputs = LightClustersPointer; + using Input = render::VaryingSet4; + using Output = LightClustersPointer; using Config = LightClusteringPassConfig; - using JobModel = render::Job::ModelIO; + using JobModel = render::Job::ModelIO; LightClusteringPass(); void configure(const Config& config); - void run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& output); + void run(const render::RenderContextPointer& renderContext, const Input& input, Output& output); protected: LightClustersPointer _lightClusters; @@ -213,7 +213,7 @@ protected: class DebugLightClusters { public: - using Inputs = render::VaryingSet5 < DeferredFrameTransformPointer, DeferredFramebufferPointer, LightingModelPointer, LinearDepthFramebufferPointer, LightClustersPointer>; + using Inputs = render::VaryingSet4 < DeferredFrameTransformPointer, LightingModelPointer, LinearDepthFramebufferPointer, LightClustersPointer>; using Config = DebugLightClustersConfig; using JobModel = render::Job::ModelI; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 223efbeba4..a6242cd84e 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -84,7 +84,7 @@ public: class RenderDeferredTaskDebug { public: using Input = render::VaryingSet9; // using Config = RenderDeferredTaskConfig; using JobModel = render::Task::ModelI; @@ -112,18 +112,6 @@ void RenderDeferredTask::configure(const Config& config) { upsamplePrimaryBufferConfig->setProperty("factor", 1.0f / config.resolutionScale); } -const render::Varying RenderDeferredTask::addSelectItemJobs(JobModel& task, const char* selectionName, - const render::Varying& metas, - const render::Varying& opaques, - const render::Varying& transparents) { - const auto selectMetaInput = SelectItems::Inputs(metas, Varying(), std::string()).asVarying(); - const auto selectedMetas = task.addJob("MetaSelection", selectMetaInput, selectionName); - const auto selectMetaAndOpaqueInput = SelectItems::Inputs(opaques, selectedMetas, std::string()).asVarying(); - const auto selectedMetasAndOpaques = task.addJob("OpaqueSelection", selectMetaAndOpaqueInput, selectionName); - const auto selectItemInput = SelectItems::Inputs(transparents, selectedMetasAndOpaques, std::string()).asVarying(); - return task.addJob("TransparentSelection", selectItemInput, selectionName); -} - void RenderDeferredTask::build(JobModel& task, const render::Varying& input, render::Varying& output, bool renderShadows) { const auto& inputs = input.get(); const auto& fetchedItems = inputs.get0(); @@ -220,7 +208,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren // Light Clustering // Create the cluster grid of lights, cpu job for now - const auto lightClusteringPassInputs = LightClusteringPass::Inputs(deferredFrameTransform, lightingModel, lightFrame, linearDepthTarget).asVarying(); + const auto lightClusteringPassInputs = LightClusteringPass::Input(deferredFrameTransform, lightingModel, lightFrame, linearDepthTarget).asVarying(); const auto lightClusters = task.addJob("LightClustering", lightClusteringPassInputs); // DeferredBuffer is complete, now let's shade it into the LightingBuffer @@ -239,16 +227,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto transparentsInputs = DrawDeferred::Inputs(transparents, hazeFrame, lightFrame, lightingModel, lightClusters, jitter).asVarying(); task.addJob("DrawTransparentDeferred", transparentsInputs, shapePlumber); - // Light Cluster Grid Debuging job - { - const auto debugLightClustersInputs = DebugLightClusters::Inputs(deferredFrameTransform, deferredFramebuffer, lightingModel, linearDepthTarget, lightClusters).asVarying(); - task.addJob("DebugLightClusters", debugLightClustersInputs); - } - const auto outlineRangeTimer = task.addJob("BeginHighlightRangeTimer", "Highlight"); - // Select items that need to be outlined - const auto selectionBaseName = "contextOverlayHighlightList"; - const auto selectedItems = addSelectItemJobs(task, selectionBaseName, metas, opaques, transparents); const auto outlineInputs = DrawHighlightTask::Inputs(items, deferredFramebuffer, lightingFramebuffer, deferredFrameTransform, jitter).asVarying(); task.addJob("DrawHighlight", outlineInputs); @@ -277,7 +256,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren // Debugging task is happening in the "over" layer after tone mapping and just before HUD { // Debug the bounds of the rendered items, still look at the zbuffer - const auto debugInputs = RenderDeferredTaskDebug::Input(fetchedItems, inputs[2], zones, selectedItems, currentStageFrames, prepareDeferredOutputs, deferredFrameTransform, jitter, lightingModel).asVarying(); + const auto debugInputs = RenderDeferredTaskDebug::Input(fetchedItems, inputs[2], lightingStageInputs, lightClusters, linearDepthTarget, prepareDeferredOutputs, deferredFrameTransform, jitter, lightingModel).asVarying(); task.addJob("DebugRenderDeferredTask", debugInputs); } @@ -308,9 +287,6 @@ void RenderDeferredTaskDebug::configure(const Config& config) { }*/ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input, render::Varying& outputs) { -// RenderFetchCullSortTask::Output, RenderShadowTask::Output, -// ZoneRendererTask::Outputs, SelectItems::Outputs, FetchCurrentFrames::Outputs, -// PrepareDeferred::Outputs, GenerateDeferredFrameTransform::Output, JitterSample::Output const auto& inputs = input.get(); @@ -334,18 +310,23 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input // RenderShadowTask out const auto& renderShadowTaskOut = inputs[1]; - // Zones - const auto& zones = inputs[2]; + // Extract the Lighting Stages Current frame ( and zones) + const auto lightingStageInputs = inputs.get2(); + // Fetch the current frame stacks from all the stages + const auto stageCurrentFrames = lightingStageInputs.get0(); + const auto lightFrame = stageCurrentFrames[0]; + const auto backgroundFrame = stageCurrentFrames[1]; + const auto hazeFrame = stageCurrentFrames[2]; + const auto bloomFrame = stageCurrentFrames[3]; - // Selected objects - const auto& selectedItems = inputs[3]; + // Zones + const auto& zones = lightingStageInputs[1]; - // Stage current frames - const auto& stageCurrentFrames = inputs.get4();//[4]; - const auto lightFrame = stageCurrentFrames[0]; - const auto backgroundFrame = stageCurrentFrames[1]; - const auto hazeFrame = stageCurrentFrames[2]; - const auto bloomFrame = stageCurrentFrames[3]; + // Light CLuster + const auto& lightClusters = inputs[3]; + + // linear Depth Target + const auto& linearDepthTarget = inputs[4]; // PrepareDeferred out const auto& deferredFramebuffer = inputs[5]; @@ -360,6 +341,14 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input const auto& lightingModel = inputs[8]; + + // Light Cluster Grid Debuging job + { + const auto debugLightClustersInputs = DebugLightClusters::Inputs(deferredFrameTransform, lightingModel, linearDepthTarget, lightClusters).asVarying(); + task.addJob("DebugLightClusters", debugLightClustersInputs); + } + + { // Debug the bounds of the rendered items, still look at the zbuffer task.addJob("DrawMetaBounds", metas); task.addJob("DrawOpaqueBounds", opaques); @@ -383,6 +372,19 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input task.addJob(jobName, shadowBBox, glm::vec3(1.0f, tint, 0.0f)); } } + } + + { // Debug Selection... + // TODO: It s busted + // Select items that need to be outlined and show them + const auto selectionBaseName = "contextOverlayHighlightList"; + + const auto selectMetaInput = SelectItems::Inputs(metas, Varying(), std::string()).asVarying(); + const auto selectedMetas = task.addJob("MetaSelection", selectMetaInput, selectionBaseName); + const auto selectMetaAndOpaqueInput = SelectItems::Inputs(opaques, selectedMetas, std::string()).asVarying(); + const auto selectedMetasAndOpaques = task.addJob("OpaqueSelection", selectMetaAndOpaqueInput, selectionBaseName); + const auto selectItemInput = SelectItems::Inputs(transparents, selectedMetasAndOpaques, std::string()).asVarying(); + const auto selectedItems = task.addJob("TransparentSelection", selectItemInput, selectionBaseName); // Render.getConfig("RenderMainView.DrawSelectionBounds").enabled = true task.addJob("DrawSelectionBounds", selectedItems); diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index 81f158918c..400bd66def 100644 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -147,11 +147,6 @@ public: void build(JobModel& task, const render::Varying& input, render::Varying& output, bool renderShadows); private: - static const render::Varying addSelectItemJobs(JobModel& task, - const char* selectionName, - const render::Varying& metas, - const render::Varying& opaques, - const render::Varying& transparents); }; #endif // hifi_RenderDeferredTask_h From 34a69889d1bfc26aacffc5eccbbc40ce8790b93d Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Wed, 12 Dec 2018 09:23:39 -0800 Subject: [PATCH 15/31] shadows in 2ndary maybe --- interface/src/SecondaryCamera.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/interface/src/SecondaryCamera.cpp b/interface/src/SecondaryCamera.cpp index 102f94b63d..cd33dfd841 100644 --- a/interface/src/SecondaryCamera.cpp +++ b/interface/src/SecondaryCamera.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -204,6 +205,9 @@ public: void SecondaryCameraRenderTask::build(JobModel& task, const render::Varying& inputs, render::Varying& outputs, render::CullFunctor cullFunctor, bool isDeferred) { const auto cachedArg = task.addJob("SecondaryCamera"); + + task.addJob("RenderSecondView", cullFunctor, true, render::ItemKey::TAG_BITS_1, render::ItemKey::TAG_BITS_1); +/* const auto items = task.addJob("FetchCullSort", cullFunctor, render::ItemKey::TAG_BITS_1, render::ItemKey::TAG_BITS_1); assert(items.canCast()); @@ -218,5 +222,6 @@ void SecondaryCameraRenderTask::build(JobModel& task, const render::Varying& inp const auto renderInput = RenderForwardTask::Input(items, lightingStageFramesAndZones).asVarying(); task.addJob("Forward", renderInput); } +*/ task.addJob("EndSecondaryCamera", cachedArg); } \ No newline at end of file From 7f193d0e7cb8b3e490889b716f541f3375d3cad3 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Thu, 13 Dec 2018 00:32:59 -0800 Subject: [PATCH 16/31] WEll it sn not going to be that simple.... --- libraries/render-utils/src/RenderShadowTask.cpp | 4 ++-- libraries/render-utils/src/RenderShadowTask.h | 3 ++- libraries/render-utils/src/RenderViewTask.cpp | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libraries/render-utils/src/RenderShadowTask.cpp b/libraries/render-utils/src/RenderShadowTask.cpp index 2232deb3d6..32e277e95b 100644 --- a/libraries/render-utils/src/RenderShadowTask.cpp +++ b/libraries/render-utils/src/RenderShadowTask.cpp @@ -58,8 +58,8 @@ void RenderShadowTask::build(JobModel& task, const render::Varying& input, rende // FIXME: calling this here before the zones/lights are drawn during the deferred/forward passes means we're actually using the frames from the previous draw // Fetch the current frame stacks from all the stages - const auto currentFrames = task.addJob("FetchCurrentFrames"); - const auto lightFrame = currentFrames.getN(0); + // Starting with the Light Frame genreated in previous tasks + const auto& lightFrame = input; const auto setupOutput = task.addJob("ShadowSetup", lightFrame); const auto queryResolution = setupOutput.getN(1); diff --git a/libraries/render-utils/src/RenderShadowTask.h b/libraries/render-utils/src/RenderShadowTask.h index e90725d66d..395d304459 100644 --- a/libraries/render-utils/src/RenderShadowTask.h +++ b/libraries/render-utils/src/RenderShadowTask.h @@ -49,9 +49,10 @@ class RenderShadowTask { public: // There is one AABox per shadow cascade + using Input = LightStage::FramePointer; using Output = render::VaryingArray; using Config = RenderShadowTaskConfig; - using JobModel = render::Task::ModelO; + using JobModel = render::Task::ModelIO; RenderShadowTask() {} void build(JobModel& task, const render::Varying& inputs, render::Varying& outputs, render::CullFunctor cameraCullFunctor, uint8_t tagBits = 0x00, uint8_t tagMask = 0x00); diff --git a/libraries/render-utils/src/RenderViewTask.cpp b/libraries/render-utils/src/RenderViewTask.cpp index d9ba4e1a56..082a77b996 100644 --- a/libraries/render-utils/src/RenderViewTask.cpp +++ b/libraries/render-utils/src/RenderViewTask.cpp @@ -27,7 +27,9 @@ void RenderViewTask::build(JobModel& task, const render::Varying& input, render: if (isDeferred) { // Warning : the cull functor passed to the shadow pass should only be testing for LOD culling. If frustum culling // is performed, then casters not in the view frustum will be removed, which is not what we wish. - const auto cascadeSceneBBoxes = task.addJob("RenderShadowTask", cullFunctor, tagBits, tagMask); + const auto& ligthStageFrame = lightingStageFramesAndZones.get().get0()[0]; + const auto cascadeSceneBBoxes = task.addJob("RenderShadowTask", ligthStageFrame, cullFunctor, tagBits, tagMask); + const auto renderInput = RenderDeferredTask::Input(items, lightingStageFramesAndZones, cascadeSceneBBoxes).asVarying(); task.addJob("RenderDeferredTask", renderInput, true); } else { From 8bfca612e3d0f008ef874288c85cac502dae110e Mon Sep 17 00:00:00 2001 From: sam gateau Date: Thu, 13 Dec 2018 17:56:14 -0800 Subject: [PATCH 17/31] Separating the state view dependant from the shadow to be able to have several versions in flight --- libraries/render-utils/src/LightStage.h | 30 +++++++++++++++---- .../render-utils/src/RenderDeferredTask.cpp | 2 +- .../render-utils/src/RenderShadowTask.cpp | 23 ++++++++++---- libraries/render-utils/src/RenderShadowTask.h | 7 +++-- 4 files changed, 48 insertions(+), 14 deletions(-) diff --git a/libraries/render-utils/src/LightStage.h b/libraries/render-utils/src/LightStage.h index 5e5b6cf4fa..2ebd86960d 100644 --- a/libraries/render-utils/src/LightStage.h +++ b/libraries/render-utils/src/LightStage.h @@ -93,10 +93,15 @@ public: const graphics::LightPointer& getLight() const { return _light; } gpu::TexturePointer map; +#include "Shadows_shared.slh" + class Schema : public ShadowParameters { + public: + Schema(); + + }; protected: -#include "Shadows_shared.slh" using Cascades = std::vector; @@ -106,12 +111,7 @@ public: float _maxDistance; Cascades _cascades; - class Schema : public ShadowParameters { - public: - Schema(); - - }; UniformBufferView _schemaBuffer = nullptr; }; @@ -182,6 +182,24 @@ public: }; using FramePointer = std::shared_ptr; + class ShadowFrame { + public: + ShadowFrame() {} + + void clear() {} + + using Object = std::pair; + using Objects = std::vector; + + void pushShadow(LightStage::Index index, const gpu::BufferPointer& params, const gpu::TexturePointer& maps) { + _objects.emplace_back(params, maps); + } + + + Objects _objects; + }; + using ShadowFramePointer = std::shared_ptr; + Frame _currentFrame; Index getAmbientOffLight() { return _ambientOffLightId; } diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index a6242cd84e..c92f46ec7d 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -256,7 +256,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren // Debugging task is happening in the "over" layer after tone mapping and just before HUD { // Debug the bounds of the rendered items, still look at the zbuffer - const auto debugInputs = RenderDeferredTaskDebug::Input(fetchedItems, inputs[2], lightingStageInputs, lightClusters, linearDepthTarget, prepareDeferredOutputs, deferredFrameTransform, jitter, lightingModel).asVarying(); + const auto debugInputs = RenderDeferredTaskDebug::Input(fetchedItems, inputs.get2(), lightingStageInputs, lightClusters, linearDepthTarget, prepareDeferredOutputs, deferredFrameTransform, jitter, lightingModel).asVarying(); task.addJob("DebugRenderDeferredTask", debugInputs); } diff --git a/libraries/render-utils/src/RenderShadowTask.cpp b/libraries/render-utils/src/RenderShadowTask.cpp index 32e277e95b..82c73a1686 100644 --- a/libraries/render-utils/src/RenderShadowTask.cpp +++ b/libraries/render-utils/src/RenderShadowTask.cpp @@ -91,7 +91,7 @@ void RenderShadowTask::build(JobModel& task, const render::Varying& input, rende #endif }; - Output cascadeSceneBBoxes; + render::VaryingArray cascadeSceneBBoxes; for (auto i = 0; i < SHADOW_CASCADE_MAX_COUNT; i++) { char jobName[64]; @@ -118,10 +118,11 @@ void RenderShadowTask::build(JobModel& task, const render::Varying& input, rende cascadeSceneBBoxes[i] = culledShadowItemsAndBounds.getN(1); } - - output = render::Varying(cascadeSceneBBoxes); - task.addJob("ShadowTeardown", setupOutput); + + + output = Output(cascadeSceneBBoxes, setupOutput.getN(3)); + } static void computeNearFar(const Triangle& triangle, const Plane shadowClipPlanes[4], float& near, float& far) { @@ -315,7 +316,7 @@ void RenderShadowMap::run(const render::RenderContextPointer& renderContext, con RenderShadowSetup::RenderShadowSetup() : _cameraFrustum{ std::make_shared() }, _coarseShadowFrustum{ std::make_shared() } { - + _shadowFrameCache = std::make_shared(); } void RenderShadowSetup::configure(const Config& configuration) { @@ -374,6 +375,16 @@ void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, c bias._constant, bias._slope); } + // copy paste the values for the shadow params: + if (!_globalShadowObject.first) { + LightStage::Shadow::Schema schema; + _globalShadowObject.first = std::make_shared(sizeof(LightStage::Shadow::Schema), (const gpu::Byte*) &schema); + } + _globalShadowObject.first->setData(globalShadow->getBuffer()._size, globalShadow->getBuffer()._buffer->getData()); + + + _shadowFrameCache->pushShadow(0, _globalShadowObject.first, _globalShadowObject.second); + // Now adjust coarse frustum bounds auto frustumPosition = firstCascadeFrustum->getPosition(); auto farTopLeft = firstCascadeFrustum->getFarTopLeft() - frustumPosition; @@ -422,6 +433,8 @@ void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, c queryResolution.x = int(queryResolution.x * _coarseShadowFrustum->getWidth() / firstCascadeFrustum->getWidth()); queryResolution.y = int(queryResolution.y * _coarseShadowFrustum->getHeight() / firstCascadeFrustum->getHeight()); output.edit1() = queryResolution; + + output.edit3() = _shadowFrameCache; } } diff --git a/libraries/render-utils/src/RenderShadowTask.h b/libraries/render-utils/src/RenderShadowTask.h index 395d304459..f01f9ddd15 100644 --- a/libraries/render-utils/src/RenderShadowTask.h +++ b/libraries/render-utils/src/RenderShadowTask.h @@ -50,7 +50,7 @@ public: // There is one AABox per shadow cascade using Input = LightStage::FramePointer; - using Output = render::VaryingArray; + using Output = render::VaryingSet2, LightStage::ShadowFramePointer>; using Config = RenderShadowTaskConfig; using JobModel = render::Task::ModelIO; @@ -101,7 +101,7 @@ signals: class RenderShadowSetup { public: using Inputs = LightStage::FramePointer; - using Outputs = render::VaryingSet3; + using Outputs = render::VaryingSet4; using Config = RenderShadowSetupConfig; using JobModel = render::Job::ModelIO; @@ -118,6 +118,9 @@ private: float _slope; } _bias[SHADOW_CASCADE_MAX_COUNT]; + LightStage::ShadowFrame::Object _globalShadowObject; + LightStage::ShadowFramePointer _shadowFrameCache; + void setConstantBias(int cascadeIndex, float value); void setSlopeBias(int cascadeIndex, float value); }; From e07bc208f34849b777a544d4a4de697ec1b4c7be Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Fri, 14 Dec 2018 00:58:07 -0800 Subject: [PATCH 18/31] introducing the Shadow Stage --- .../src/DeferredLightingEffect.cpp | 4 +- .../render-utils/src/DeferredLightingEffect.h | 4 +- libraries/render-utils/src/LightStage.h | 6 +- .../render-utils/src/RenderDeferredTask.cpp | 72 ++++++++++--------- .../render-utils/src/RenderDeferredTask.h | 2 +- .../render-utils/src/RenderShadowTask.cpp | 8 +-- libraries/task/src/task/Task.h | 1 + libraries/task/src/task/Varying.h | 69 ++++++++++++++++++ 8 files changed, 123 insertions(+), 43 deletions(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index e0fd9e970d..98de378505 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -374,6 +374,7 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, const DeferredFramebufferPointer& deferredFramebuffer, const LightingModelPointer& lightingModel, const LightStage::FramePointer& lightFrame, + const LightStage::ShadowFramePointer& shadowFrame, const HazeStage::FramePointer& hazeFrame, const SurfaceGeometryFramebufferPointer& surfaceGeometryFramebuffer, const AmbientOcclusionFramebufferPointer& ambientOcclusionFramebuffer, @@ -627,7 +628,8 @@ void RenderDeferred::run(const RenderContextPointer& renderContext, const Inputs auto args = renderContext->args; const auto& lightFrame = inputs.get7(); - const auto& hazeFrame = inputs.get8(); + const auto& shadowFrame = inputs.get8(); + const auto& hazeFrame = inputs.get9(); if (!_gpuTimer) { _gpuTimer = std::make_shared < gpu::RangeTimer>(__FUNCTION__); diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 9fd9554d31..f3b97e2367 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -182,9 +182,9 @@ using RenderDeferredConfig = render::GPUJobConfig; class RenderDeferred { public: - using Inputs = render::VaryingSet9< + using Inputs = render::VaryingSet10< DeferredFrameTransformPointer, DeferredFramebufferPointer, LightingModelPointer, SurfaceGeometryFramebufferPointer, - AmbientOcclusionFramebufferPointer, SubsurfaceScatteringResourcePointer, LightClustersPointer, LightStage::FramePointer, HazeStage::FramePointer>; + AmbientOcclusionFramebufferPointer, SubsurfaceScatteringResourcePointer, LightClustersPointer, LightStage::FramePointer, LightStage::ShadowFramePointer, HazeStage::FramePointer>; using Config = RenderDeferredConfig; using JobModel = render::Job::ModelI; diff --git a/libraries/render-utils/src/LightStage.h b/libraries/render-utils/src/LightStage.h index 2ebd86960d..be187d1d49 100644 --- a/libraries/render-utils/src/LightStage.h +++ b/libraries/render-utils/src/LightStage.h @@ -188,11 +188,11 @@ public: void clear() {} - using Object = std::pair; + using Object = ShadowPointer; using Objects = std::vector; - void pushShadow(LightStage::Index index, const gpu::BufferPointer& params, const gpu::TexturePointer& maps) { - _objects.emplace_back(params, maps); + void pushShadow(const ShadowPointer& shadow) { + _objects.emplace_back(shadow); } diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index c92f46ec7d..f3841e4d4c 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -113,42 +113,48 @@ void RenderDeferredTask::configure(const Config& config) { } void RenderDeferredTask::build(JobModel& task, const render::Varying& input, render::Varying& output, bool renderShadows) { - const auto& inputs = input.get(); - const auto& fetchedItems = inputs.get0(); - // const auto& fetchedItems = inputs[0]; - // const auto& items = fetchedItems[0]; - const auto& items = fetchedItems.get0(); - auto fadeEffect = DependencyManager::get(); - // Prepare the ShapePipelines ShapePlumberPointer shapePlumber = std::make_shared(); initDeferredPipelines(*shapePlumber, fadeEffect->getBatchSetter(), fadeEffect->getItemUniformSetter()); - // Extract opaques / transparents / lights / metas / overlays / background - const auto& opaques = items[RenderFetchCullSortTask::OPAQUE_SHAPE]; - const auto& transparents = items[RenderFetchCullSortTask::TRANSPARENT_SHAPE]; - const auto& lights = items[RenderFetchCullSortTask::LIGHT]; - const auto& metas = items[RenderFetchCullSortTask::META]; - const auto& overlayOpaques = items[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; - const auto& overlayTransparents = items[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; - const auto& overlaysInFrontOpaque = items[RenderFetchCullSortTask::LAYER_FRONT_OPAQUE_SHAPE]; - const auto& overlaysInFrontTransparent = items[RenderFetchCullSortTask::LAYER_FRONT_TRANSPARENT_SHAPE]; - const auto& overlaysHUDOpaque = items[RenderFetchCullSortTask::LAYER_HUD_OPAQUE_SHAPE]; - const auto& overlaysHUDTransparent = items[RenderFetchCullSortTask::LAYER_HUD_TRANSPARENT_SHAPE]; + const auto& inputs = input.get(); + + // Separate the fetched items + const auto& fetchedItems = inputs.get0(); - const auto& spatialSelection = fetchedItems[1]; + const auto& items = fetchedItems.get0(); + + // Extract opaques / transparents / lights / metas / overlays / background + const auto& opaques = items[RenderFetchCullSortTask::OPAQUE_SHAPE]; + const auto& transparents = items[RenderFetchCullSortTask::TRANSPARENT_SHAPE]; + const auto& lights = items[RenderFetchCullSortTask::LIGHT]; + const auto& metas = items[RenderFetchCullSortTask::META]; + const auto& overlayOpaques = items[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; + const auto& overlayTransparents = items[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; + const auto& overlaysInFrontOpaque = items[RenderFetchCullSortTask::LAYER_FRONT_OPAQUE_SHAPE]; + const auto& overlaysInFrontTransparent = items[RenderFetchCullSortTask::LAYER_FRONT_TRANSPARENT_SHAPE]; + const auto& overlaysHUDOpaque = items[RenderFetchCullSortTask::LAYER_HUD_OPAQUE_SHAPE]; + const auto& overlaysHUDTransparent = items[RenderFetchCullSortTask::LAYER_HUD_TRANSPARENT_SHAPE]; + + const auto& spatialSelection = fetchedItems.get1(); // Extract the Lighting Stages Current frame ( and zones) const auto lightingStageInputs = inputs.get1(); - // Fetch the current frame stacks from all the stages - const auto currentStageFrames = lightingStageInputs.get0(); - const auto lightFrame = currentStageFrames[0]; - const auto backgroundFrame = currentStageFrames[1]; - const auto& hazeFrame = currentStageFrames[2]; - const auto& bloomFrame = currentStageFrames[3]; - - const auto& zones = lightingStageInputs[1]; + // Fetch the current frame stacks from all the stages + const auto currentStageFrames = lightingStageInputs.get0(); + const auto lightFrame = currentStageFrames[0]; + const auto backgroundFrame = currentStageFrames[1]; + const auto& hazeFrame = currentStageFrames[2]; + const auto& bloomFrame = currentStageFrames[3]; + + const auto& zones = lightingStageInputs[1]; + + // Shadow Task Outputs + const auto shadowTaskOutputs = inputs.get2(); + + // Shadow Stage Frame + const auto shadowFrame = shadowTaskOutputs.get1(); fadeEffect->build(task, opaques); @@ -213,7 +219,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren // DeferredBuffer is complete, now let's shade it into the LightingBuffer const auto deferredLightingInputs = RenderDeferred::Inputs(deferredFrameTransform, deferredFramebuffer, lightingModel, - surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, scatteringResource, lightClusters, lightFrame, hazeFrame).asVarying(); + surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, scatteringResource, lightClusters, lightFrame, shadowFrame, hazeFrame).asVarying(); task.addJob("RenderDeferred", deferredLightingInputs, renderShadows); // Similar to light stage, background stage has been filled by several potential render items and resolved for the frame in this job @@ -224,7 +230,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren task.addJob("DrawHazeDeferred", drawHazeInputs); // Render transparent objects forward in LightingBuffer - const auto transparentsInputs = DrawDeferred::Inputs(transparents, hazeFrame, lightFrame, lightingModel, lightClusters, jitter).asVarying(); + const auto transparentsInputs = DrawDeferred::Inputs(transparents, hazeFrame, lightFrame, lightingModel, lightClusters, shadowFrame, jitter).asVarying(); task.addJob("DrawTransparentDeferred", transparentsInputs, shapePlumber); const auto outlineRangeTimer = task.addJob("BeginHighlightRangeTimer", "Highlight"); @@ -279,7 +285,6 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren } RenderDeferredTaskDebug::RenderDeferredTaskDebug() { - } /* void RenderDeferredTaskDebug::configure(const Config& config) { @@ -308,7 +313,9 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input const auto& overlaysHUDTransparent = items[RenderFetchCullSortTask::LAYER_HUD_TRANSPARENT_SHAPE]; // RenderShadowTask out - const auto& renderShadowTaskOut = inputs[1]; + const auto& shadowOut = inputs.get1(); + + const auto& renderShadowTaskOut = inputs[0]; // Extract the Lighting Stages Current frame ( and zones) const auto lightingStageInputs = inputs.get2(); @@ -448,7 +455,8 @@ void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs& const auto& lightFrame = inputs.get2(); const auto& lightingModel = inputs.get3(); const auto& lightClusters = inputs.get4(); - const auto jitter = inputs.get5(); + const auto& shadowFrame = inputs.get5(); + const auto jitter = inputs.get6(); auto deferredLightingEffect = DependencyManager::get(); RenderArgs* args = renderContext->args; diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index 400bd66def..be204ef6a5 100644 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -43,7 +43,7 @@ protected: class DrawDeferred { public: - using Inputs = render::VaryingSet6; + using Inputs = render::VaryingSet7; using Config = DrawDeferredConfig; using JobModel = render::Job::ModelI; diff --git a/libraries/render-utils/src/RenderShadowTask.cpp b/libraries/render-utils/src/RenderShadowTask.cpp index 82c73a1686..12dfecd855 100644 --- a/libraries/render-utils/src/RenderShadowTask.cpp +++ b/libraries/render-utils/src/RenderShadowTask.cpp @@ -376,14 +376,14 @@ void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, c } // copy paste the values for the shadow params: - if (!_globalShadowObject.first) { + /* if (!_globalShadowObject) { LightStage::Shadow::Schema schema; - _globalShadowObject.first = std::make_shared(sizeof(LightStage::Shadow::Schema), (const gpu::Byte*) &schema); + _globalShadowObject = std::make_shared(sizeof(LightStage::Shadow::Schema), (const gpu::Byte*) &schema); } - _globalShadowObject.first->setData(globalShadow->getBuffer()._size, globalShadow->getBuffer()._buffer->getData()); + _globalShadowObject->getBuffersetData(globalShadow->getBuffer()._size, globalShadow->getBuffer()._buffer->getData()); - _shadowFrameCache->pushShadow(0, _globalShadowObject.first, _globalShadowObject.second); + _shadowFrameCache->pushShadow(_globalShadowObject);*/ // Now adjust coarse frustum bounds auto frustumPosition = firstCascadeFrustum->getPosition(); diff --git a/libraries/task/src/task/Task.h b/libraries/task/src/task/Task.h index b00e5a8de7..632e8a222e 100644 --- a/libraries/task/src/task/Task.h +++ b/libraries/task/src/task/Task.h @@ -419,6 +419,7 @@ protected: template < typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6 > using VaryingSet7 = task::VaryingSet7; \ template < typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7 > using VaryingSet8 = task::VaryingSet8; \ template < typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8 > using VaryingSet9 = task::VaryingSet9; \ + template < typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9 > using VaryingSet10 = task::VaryingSet10; \ template < class T, int NUM > using VaryingArray = task::VaryingArray; diff --git a/libraries/task/src/task/Varying.h b/libraries/task/src/task/Varying.h index c81d8b6753..18edf35937 100644 --- a/libraries/task/src/task/Varying.h +++ b/libraries/task/src/task/Varying.h @@ -440,6 +440,75 @@ public: Varying asVarying() const { return Varying((*this)); } }; + +template +class VaryingSet10 : public std::tuple { +public: + using Parent = std::tuple; + + VaryingSet10() : Parent(Varying(T0()), Varying(T1()), Varying(T2()), Varying(T3()), Varying(T4()), Varying(T5()), Varying(T6()), Varying(T7()), Varying(T8()), Varying(T9())) {} + VaryingSet10(const VaryingSet10& src) : Parent(std::get<0>(src), std::get<1>(src), std::get<2>(src), std::get<3>(src), std::get<4>(src), std::get<5>(src), std::get<6>(src), std::get<7>(src), std::get<8>(src), std::get<9>(src)) {} + VaryingSet10(const Varying& first, const Varying& second, const Varying& third, const Varying& fourth, const Varying& fifth, const Varying& sixth, const Varying& seventh, const Varying& eighth, const Varying& nine, const Varying& ten) : Parent(first, second, third, fourth, fifth, sixth, seventh, eighth, nine, ten) {} + + const T0& get0() const { return std::get<0>((*this)).template get(); } + T0& edit0() { return std::get<0>((*this)).template edit(); } + + const T1& get1() const { return std::get<1>((*this)).template get(); } + T1& edit1() { return std::get<1>((*this)).template edit(); } + + const T2& get2() const { return std::get<2>((*this)).template get(); } + T2& edit2() { return std::get<2>((*this)).template edit(); } + + const T3& get3() const { return std::get<3>((*this)).template get(); } + T3& edit3() { return std::get<3>((*this)).template edit(); } + + const T4& get4() const { return std::get<4>((*this)).template get(); } + T4& edit4() { return std::get<4>((*this)).template edit(); } + + const T5& get5() const { return std::get<5>((*this)).template get(); } + T5& edit5() { return std::get<5>((*this)).template edit(); } + + const T6& get6() const { return std::get<6>((*this)).template get(); } + T6& edit6() { return std::get<6>((*this)).template edit(); } + + const T7& get7() const { return std::get<7>((*this)).template get(); } + T7& edit7() { return std::get<7>((*this)).template edit(); } + + const T8& get8() const { return std::get<8>((*this)).template get(); } + T8& edit8() { return std::get<8>((*this)).template edit(); } + + const T9& get9() const { return std::get<9>((*this)).template get(); } + T9& edit9() { return std::get<9>((*this)).template edit(); } + + virtual Varying operator[] (uint8_t index) const { + switch (index) { + default: + return std::get<0>((*this)); + case 1: + return std::get<1>((*this)); + case 2: + return std::get<2>((*this)); + case 3: + return std::get<3>((*this)); + case 4: + return std::get<4>((*this)); + case 5: + return std::get<5>((*this)); + case 6: + return std::get<6>((*this)); + case 7: + return std::get<7>((*this)); + case 8: + return std::get<8>((*this)); + case 9: + return std::get<9>((*this)); + }; + } + virtual uint8_t length() const { return 10; } + + Varying asVarying() const { return Varying((*this)); } +}; + template < class T, int NUM > class VaryingArray : public std::array { public: From 0b03012e5e2f2a3ad6e83bdebe40b0e1d6cb5df4 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Fri, 14 Dec 2018 06:55:34 -0800 Subject: [PATCH 19/31] introducing the Shadow Stage --- libraries/render-utils/src/DeferredLightingEffect.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index f3b97e2367..7f6f92ff90 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -146,6 +146,7 @@ public: const DeferredFramebufferPointer& deferredFramebuffer, const LightingModelPointer& lightingModel, const LightStage::FramePointer& lightFrame, + const LightStage::ShadowFramePointer& shadowFrame, const HazeStage::FramePointer& hazeFrame, const SurfaceGeometryFramebufferPointer& surfaceGeometryFramebuffer, const AmbientOcclusionFramebufferPointer& ambientOcclusionFramebuffer, From a4b9ec50e95c73462d1432c34fe93a791c736260 Mon Sep 17 00:00:00 2001 From: sam gateau Date: Fri, 14 Dec 2018 17:00:58 -0800 Subject: [PATCH 20/31] one step closer --- .../src/DeferredLightingEffect.cpp | 8 +- libraries/render-utils/src/LightStage.cpp | 5 ++ libraries/render-utils/src/LightStage.h | 2 + .../render-utils/src/RenderDeferredTask.cpp | 2 +- .../render-utils/src/RenderShadowTask.cpp | 82 +++++++++++-------- libraries/render-utils/src/RenderShadowTask.h | 2 +- 6 files changed, 62 insertions(+), 39 deletions(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 98de378505..78cd10ca52 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -436,7 +436,11 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, assert(lightStage); assert(lightStage->getNumLights() > 0); auto lightAndShadow = lightStage->getCurrentKeyLightAndShadow(*lightFrame); - const auto& globalShadow = lightAndShadow.second; + //const auto& globalShadow = lightAndShadow.second; + LightStage::ShadowPointer globalShadow; + if (shadowFrame && !shadowFrame->_objects.empty()) { + globalShadow = shadowFrame->_objects.front(); + } // Bind the shadow buffers if (globalShadow) { @@ -640,7 +644,7 @@ void RenderDeferred::run(const RenderContextPointer& renderContext, const Inputs args->_batch = &batch; _gpuTimer->begin(batch); - setupJob.run(renderContext, deferredTransform, deferredFramebuffer, lightingModel, lightFrame, hazeFrame, surfaceGeometryFramebuffer, ssaoFramebuffer, subsurfaceScatteringResource, _renderShadows); + setupJob.run(renderContext, deferredTransform, deferredFramebuffer, lightingModel, lightFrame, shadowFrame, hazeFrame, surfaceGeometryFramebuffer, ssaoFramebuffer, subsurfaceScatteringResource, _renderShadows); lightsJob.run(renderContext, deferredTransform, deferredFramebuffer, lightingModel, surfaceGeometryFramebuffer, lightClusters); diff --git a/libraries/render-utils/src/LightStage.cpp b/libraries/render-utils/src/LightStage.cpp index d5e1ca4644..ad3a86507e 100644 --- a/libraries/render-utils/src/LightStage.cpp +++ b/libraries/render-utils/src/LightStage.cpp @@ -152,6 +152,11 @@ LightStage::Shadow::Shadow(graphics::LightPointer light, float maxDistance, unsi setMaxDistance(maxDistance); } +void LightStage::Shadow::setLight(graphics::LightPointer light) { + _light = light; +} + + void LightStage::Shadow::setMaxDistance(float value) { // This overlaping factor isn't really used directly for blending of shadow cascades. It // just there to be sure the cascades do overlap. The blending width used is relative diff --git a/libraries/render-utils/src/LightStage.h b/libraries/render-utils/src/LightStage.h index be187d1d49..6c84859164 100644 --- a/libraries/render-utils/src/LightStage.h +++ b/libraries/render-utils/src/LightStage.h @@ -76,6 +76,8 @@ public: Shadow(graphics::LightPointer light, float maxDistance, unsigned int cascadeCount = 1); + void setLight(graphics::LightPointer light); + void setKeylightFrustum(const ViewFrustum& viewFrustum, float nearDepth = 1.0f, float farDepth = 1000.0f); void setKeylightCascadeFrustum(unsigned int cascadeIndex, const ViewFrustum& viewFrustum, diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index f3841e4d4c..78ad5fa2d3 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -154,7 +154,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto shadowTaskOutputs = inputs.get2(); // Shadow Stage Frame - const auto shadowFrame = shadowTaskOutputs.get1(); + const auto shadowFrame = shadowTaskOutputs[1]; fadeEffect->build(task, opaques); diff --git a/libraries/render-utils/src/RenderShadowTask.cpp b/libraries/render-utils/src/RenderShadowTask.cpp index 12dfecd855..31f5084589 100644 --- a/libraries/render-utils/src/RenderShadowTask.cpp +++ b/libraries/render-utils/src/RenderShadowTask.cpp @@ -63,6 +63,7 @@ void RenderShadowTask::build(JobModel& task, const render::Varying& input, rende const auto setupOutput = task.addJob("ShadowSetup", lightFrame); const auto queryResolution = setupOutput.getN(1); + const auto shadowFrame = setupOutput.getN(3); // Fetch and cull the items from the scene static const auto shadowCasterReceiverFilter = ItemFilter::Builder::visibleWorldItems().withTypeShape().withOpaque().withoutLayered().withTagBits(tagBits, tagMask); @@ -96,7 +97,7 @@ void RenderShadowTask::build(JobModel& task, const render::Varying& input, rende for (auto i = 0; i < SHADOW_CASCADE_MAX_COUNT; i++) { char jobName[64]; sprintf(jobName, "ShadowCascadeSetup%d", i); - const auto cascadeSetupOutput = task.addJob(jobName, lightFrame, i, tagBits, tagMask); + const auto cascadeSetupOutput = task.addJob(jobName, shadowFrame, i, tagBits, tagMask); const auto shadowFilter = cascadeSetupOutput.getN(0); auto antiFrustum = render::Varying(ViewFrustumPointer()); cascadeFrustums[i] = cascadeSetupOutput.getN(1); @@ -359,31 +360,30 @@ void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, c *_cameraFrustum = args->getViewFrustum(); output.edit2() = _cameraFrustum; - const auto globalShadow = lightStage->getCurrentKeyShadow(lightFrame); - if (globalShadow) { - globalShadow->setKeylightFrustum(args->getViewFrustum(), SHADOW_FRUSTUM_NEAR, SHADOW_FRUSTUM_FAR); + // Clear previous shadow frame + if (!_globalShadowObject) { + _globalShadowObject = std::make_shared(graphics::LightPointer(), 100.0f); + } + _shadowFrameCache->_objects.clear(); + + const auto theGlobalShadow = lightStage->getCurrentKeyShadow(lightFrame); + if (theGlobalShadow) { + _globalShadowObject->setLight(theGlobalShadow->getLight()); + _globalShadowObject->setKeylightFrustum(args->getViewFrustum(), SHADOW_FRUSTUM_NEAR, SHADOW_FRUSTUM_FAR); - auto& firstCascade = globalShadow->getCascade(0); + auto& firstCascade = _globalShadowObject->getCascade(0); auto& firstCascadeFrustum = firstCascade.getFrustum(); unsigned int cascadeIndex; // Adjust each cascade frustum - for (cascadeIndex = 0; cascadeIndex < globalShadow->getCascadeCount(); ++cascadeIndex) { + for (cascadeIndex = 0; cascadeIndex < _globalShadowObject->getCascadeCount(); ++cascadeIndex) { auto& bias = _bias[cascadeIndex]; - globalShadow->setKeylightCascadeFrustum(cascadeIndex, args->getViewFrustum(), + _globalShadowObject->setKeylightCascadeFrustum(cascadeIndex, args->getViewFrustum(), SHADOW_FRUSTUM_NEAR, SHADOW_FRUSTUM_FAR, bias._constant, bias._slope); } - // copy paste the values for the shadow params: - /* if (!_globalShadowObject) { - LightStage::Shadow::Schema schema; - _globalShadowObject = std::make_shared(sizeof(LightStage::Shadow::Schema), (const gpu::Byte*) &schema); - } - _globalShadowObject->getBuffersetData(globalShadow->getBuffer()._size, globalShadow->getBuffer()._buffer->getData()); - - - _shadowFrameCache->pushShadow(_globalShadowObject);*/ + _shadowFrameCache->pushShadow(_globalShadowObject); // Now adjust coarse frustum bounds auto frustumPosition = firstCascadeFrustum->getPosition(); @@ -397,8 +397,8 @@ void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, c auto near = firstCascadeFrustum->getNearClip(); auto far = firstCascadeFrustum->getFarClip(); - for (cascadeIndex = 1; cascadeIndex < globalShadow->getCascadeCount(); ++cascadeIndex) { - auto& cascadeFrustum = globalShadow->getCascade(cascadeIndex).getFrustum(); + for (cascadeIndex = 1; cascadeIndex < _globalShadowObject->getCascadeCount(); ++cascadeIndex) { + auto& cascadeFrustum = _globalShadowObject->getCascade(cascadeIndex).getFrustum(); farTopLeft = cascadeFrustum->getFarTopLeft() - frustumPosition; farBottomRight = cascadeFrustum->getFarBottomRight() - frustumPosition; @@ -439,36 +439,48 @@ void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, c } void RenderShadowCascadeSetup::run(const render::RenderContextPointer& renderContext, const Inputs& input, Outputs& output) { + const auto shadowFrame = input; + /* auto lightStage = renderContext->_scene->getStage(); const auto& lightFrame = *input; assert(lightStage); - +*/ // Cache old render args RenderArgs* args = renderContext->args; RenderShadowTask::CullFunctor cullFunctor; - const auto globalShadow = lightStage->getCurrentKeyShadow(lightFrame); - if (globalShadow && _cascadeIndex < globalShadow->getCascadeCount()) { - // Second item filter is to filter items to keep in shadow frustum computation (here we need to keep shadow receivers) - output.edit0() = ItemFilter::Builder::visibleWorldItems().withTypeShape().withOpaque().withoutLayered().withTagBits(_tagBits, _tagMask); + + if (shadowFrame && !shadowFrame->_objects.empty() && shadowFrame->_objects[0]) { + const auto globalShadow = shadowFrame->_objects[0]; //lightStage->getCurrentKeyShadow(lightFrame); - // Set the keylight render args - auto& cascade = globalShadow->getCascade(_cascadeIndex); - auto& cascadeFrustum = cascade.getFrustum(); - args->pushViewFrustum(*cascadeFrustum); - auto texelSize = glm::min(cascadeFrustum->getHeight(), cascadeFrustum->getWidth()) / cascade.framebuffer->getSize().x; - // Set the cull threshold to 24 shadow texels. This is totally arbitrary - const auto minTexelCount = 24.0f; - // TODO : maybe adapt that with LOD management system? - texelSize *= minTexelCount; - cullFunctor._minSquareSize = texelSize * texelSize; + if (globalShadow && _cascadeIndex < globalShadow->getCascadeCount()) { + // Second item filter is to filter items to keep in shadow frustum computation (here we need to keep shadow receivers) + output.edit0() = ItemFilter::Builder::visibleWorldItems().withTypeShape().withOpaque().withoutLayered().withTagBits(_tagBits, _tagMask); - output.edit1() = cascadeFrustum; - } else { + // Set the keylight render args + auto& cascade = globalShadow->getCascade(_cascadeIndex); + auto& cascadeFrustum = cascade.getFrustum(); + args->pushViewFrustum(*cascadeFrustum); + auto texelSize = glm::min(cascadeFrustum->getHeight(), cascadeFrustum->getWidth()) / cascade.framebuffer->getSize().x; + // Set the cull threshold to 24 shadow texels. This is totally arbitrary + const auto minTexelCount = 24.0f; + // TODO : maybe adapt that with LOD management system? + texelSize *= minTexelCount; + cullFunctor._minSquareSize = texelSize * texelSize; + + output.edit1() = cascadeFrustum; + + } else { + output.edit0() = ItemFilter::Builder::nothing(); + output.edit1() = ViewFrustumPointer(); + } + } + else { output.edit0() = ItemFilter::Builder::nothing(); output.edit1() = ViewFrustumPointer(); } + output.edit2() = cullFunctor; } diff --git a/libraries/render-utils/src/RenderShadowTask.h b/libraries/render-utils/src/RenderShadowTask.h index f01f9ddd15..1ac5f27087 100644 --- a/libraries/render-utils/src/RenderShadowTask.h +++ b/libraries/render-utils/src/RenderShadowTask.h @@ -127,7 +127,7 @@ private: class RenderShadowCascadeSetup { public: - using Inputs = LightStage::FramePointer; + using Inputs = LightStage::ShadowFramePointer; using Outputs = render::VaryingSet3; using JobModel = render::Job::ModelIO; From 318bf20ede0555b5d8ad4e764fd014e3311a7f00 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 17 Dec 2018 00:27:07 -0800 Subject: [PATCH 21/31] Shadow is working correctly in both pipelines --- .../src/RenderableZoneEntityItem.cpp | 2 +- .../src/AmbientOcclusionEffect.cpp | 2 - .../src/DeferredLightingEffect.cpp | 51 +++++++------------ .../render-utils/src/DeferredLightingEffect.h | 10 ++-- libraries/render-utils/src/LightingModel.cpp | 21 ++++++++ libraries/render-utils/src/LightingModel.h | 18 +++++++ .../render-utils/src/RenderShadowTask.cpp | 24 +++++---- libraries/render-utils/src/RenderShadowTask.h | 2 +- .../utilities/render/deferredLighting.qml | 4 +- 9 files changed, 80 insertions(+), 54 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index 95f390931b..0986f35d8d 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -100,7 +100,7 @@ void ZoneEntityRenderer::doRender(RenderArgs* args) { // Do we need to allocate the light in the stage ? if (LightStage::isIndexInvalid(_sunIndex)) { _sunIndex = _stage->addLight(_sunLight); - _shadowIndex = _stage->addShadow(_sunIndex, SUN_SHADOW_MAX_DISTANCE, SUN_SHADOW_CASCADE_COUNT); + // _shadowIndex = _stage->addShadow(_sunIndex, SUN_SHADOW_MAX_DISTANCE, SUN_SHADOW_CASCADE_COUNT); } else { _stage->updateLightArrayBuffer(_sunIndex); } diff --git a/libraries/render-utils/src/AmbientOcclusionEffect.cpp b/libraries/render-utils/src/AmbientOcclusionEffect.cpp index bbb370010e..c8f6831376 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.cpp +++ b/libraries/render-utils/src/AmbientOcclusionEffect.cpp @@ -303,8 +303,6 @@ AmbientOcclusionEffect::AmbientOcclusionEffect() { } void AmbientOcclusionEffect::configure(const Config& config) { - DependencyManager::get()->setAmbientOcclusionEnabled(config.isEnabled()); - bool shouldUpdateBlurs = false; bool shouldUpdateTechnique = false; diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 78cd10ca52..bc7fdb06e7 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -405,7 +405,7 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, batch.setResourceTexture(ru::Texture::DeferredDepth, deferredFramebuffer->getPrimaryDepthTexture()); // FIXME: Different render modes should have different tasks - if (args->_renderMode == RenderArgs::DEFAULT_RENDER_MODE && deferredLightingEffect->isAmbientOcclusionEnabled() && ambientOcclusionFramebuffer) { + if (lightingModel->isAmbientOcclusionEnabled() && ambientOcclusionFramebuffer) { batch.setResourceTexture(ru::Texture::DeferredObscurance, ambientOcclusionFramebuffer->getOcclusionTexture()); } else { // need to assign the white texture if ao is off @@ -430,28 +430,23 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, batch.setResourceTexture(ru::Texture::SsscSpecularBeckmann, subsurfaceScatteringResource->getScatteringSpecular()); } - // Global directional light and ambient pass - + // Global directional light, maybe shadow and ambient pass auto lightStage = renderContext->_scene->getStage(); assert(lightStage); assert(lightStage->getNumLights() > 0); - auto lightAndShadow = lightStage->getCurrentKeyLightAndShadow(*lightFrame); - //const auto& globalShadow = lightAndShadow.second; + auto keyLight = lightStage->getCurrentKeyLight(*lightFrame); + + // Check if keylight casts shadows + bool keyLightCastShadows{ false }; LightStage::ShadowPointer globalShadow; - if (shadowFrame && !shadowFrame->_objects.empty()) { + if (lightingModel->isShadowEnabled() && shadowFrame && !shadowFrame->_objects.empty()) { globalShadow = shadowFrame->_objects.front(); + if (globalShadow) { + keyLightCastShadows = true; + } } - // Bind the shadow buffers - if (globalShadow) { - batch.setResourceTexture(ru::Texture::Shadow, globalShadow->map); - } - - auto program = deferredLightingEffect->_directionalSkyboxLight; - LightLocationsPtr locations = deferredLightingEffect->_directionalSkyboxLightLocations; - - auto keyLight = lightAndShadow.first; - + // Global Ambient light graphics::LightPointer ambientLight; if (lightStage && lightFrame->_ambientLights.size()) { ambientLight = lightStage->getLight(lightFrame->_ambientLights.front()); @@ -459,18 +454,10 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, bool hasAmbientMap = (ambientLight != nullptr); // Setup the global directional pass pipeline + auto program = deferredLightingEffect->_directionalSkyboxLight; + LightLocationsPtr locations = deferredLightingEffect->_directionalSkyboxLightLocations; { - // Check if keylight casts shadows - bool keyLightCastShadows { false }; - - if (renderShadows && lightStage && lightFrame->_sunLights.size()) { - graphics::LightPointer keyLight = lightStage->getLight(lightFrame->_sunLights.front()); - if (keyLight) { - keyLightCastShadows = keyLight->getCastShadows(); - } - } - - if (deferredLightingEffect->_shadowMapEnabled && keyLightCastShadows) { + if (keyLightCastShadows) { // If the keylight has an ambient Map then use the Skybox version of the pass // otherwise use the ambient sphere version @@ -493,7 +480,8 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, } } - if (locations->shadowTransform && globalShadow) { + if (keyLightCastShadows && globalShadow) { + batch.setResourceTexture(ru::Texture::Shadow, globalShadow->map); batch.setUniformBuffer(ru::Buffer::ShadowParams, globalShadow->getBuffer()); } @@ -515,10 +503,7 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, batch.draw(gpu::TRIANGLE_STRIP, 4); deferredLightingEffect->unsetKeyLightBatch(batch); - - for (auto i = 0; i < SHADOW_CASCADE_MAX_COUNT; i++) { - batch.setResourceTexture(ru::Texture::Shadow +i, nullptr); - } + batch.setResourceTexture(ru::Texture::Shadow, nullptr); } } @@ -702,7 +687,7 @@ void DefaultLightingSetup::run(const RenderContextPointer& renderContext) { // Add the global light to the light stage (for later shadow rendering) // Set this light to be the default _defaultLightID = lightStage->addLight(lp, true); - lightStage->addShadow(_defaultLightID); + // lightStage->addShadow(_defaultLightID); } auto backgroundStage = renderContext->_scene->getStage(); diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 7f6f92ff90..1379b7dc89 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -55,15 +55,15 @@ public: static void setupLocalLightsBatch(gpu::Batch& batch, const LightClustersPointer& lightClusters); static void unsetLocalLightsBatch(gpu::Batch& batch); - void setShadowMapEnabled(bool enable) { _shadowMapEnabled = enable; }; - void setAmbientOcclusionEnabled(bool enable) { _ambientOcclusionEnabled = enable; } - bool isAmbientOcclusionEnabled() const { return _ambientOcclusionEnabled; } + // void setShadowMapEnabled(bool enable) { _shadowMapEnabled = enable; }; +// void setAmbientOcclusionEnabled(bool enable) { _ambientOcclusionEnabled = enable; } + // bool isAmbientOcclusionEnabled() const { return _ambientOcclusionEnabled; } private: DeferredLightingEffect() = default; - bool _shadowMapEnabled{ true }; // note that this value is overwritten in the ::configure method - bool _ambientOcclusionEnabled{ false }; +// bool _shadowMapEnabled{ true }; // note that this value is overwritten in the ::configure method + // bool _ambientOcclusionEnabled{ false }; graphics::MeshPointer _pointLightMesh; graphics::MeshPointer getPointLightMesh(); diff --git a/libraries/render-utils/src/LightingModel.cpp b/libraries/render-utils/src/LightingModel.cpp index 05002a5daf..2a85fcd960 100644 --- a/libraries/render-utils/src/LightingModel.cpp +++ b/libraries/render-utils/src/LightingModel.cpp @@ -187,6 +187,24 @@ bool LightingModel::isBlendshapeEnabled() const { return (bool)_parametersBuffer.get().enableBlendshape; } +void LightingModel::setAmbientOcclusion(bool enable) { + if (enable != isAmbientOcclusionEnabled()) { + _parametersBuffer.edit().enableAmbientOcclusion = (float)enable; + } +} +bool LightingModel::isAmbientOcclusionEnabled() const { + return (bool)_parametersBuffer.get().enableAmbientOcclusion; +} + +void LightingModel::setShadow(bool enable) { + if (enable != isShadowEnabled()) { + _parametersBuffer.edit().enableShadow = (float)enable; + } +} +bool LightingModel::isShadowEnabled() const { + return (bool)_parametersBuffer.get().enableShadow; +} + MakeLightingModel::MakeLightingModel() { _lightingModel = std::make_shared(); } @@ -218,6 +236,9 @@ void MakeLightingModel::configure(const Config& config) { _lightingModel->setSkinning(config.enableSkinning); _lightingModel->setBlendshape(config.enableBlendshape); + + _lightingModel->setAmbientOcclusion(config.enableAmbientOcclusion); + _lightingModel->setShadow(config.enableShadow); } void MakeLightingModel::run(const render::RenderContextPointer& renderContext, LightingModelPointer& lightingModel) { diff --git a/libraries/render-utils/src/LightingModel.h b/libraries/render-utils/src/LightingModel.h index de7ff63972..995c7cdfb7 100644 --- a/libraries/render-utils/src/LightingModel.h +++ b/libraries/render-utils/src/LightingModel.h @@ -76,6 +76,12 @@ public: void setBlendshape(bool enable); bool isBlendshapeEnabled() const; + + void setAmbientOcclusion(bool enable); + bool isAmbientOcclusionEnabled() const; + void setShadow(bool enable); + bool isShadowEnabled() const; + UniformBufferView getParametersBuffer() const { return _parametersBuffer; } protected: @@ -112,6 +118,11 @@ protected: float enableSkinning{ 1.0f }; float enableBlendshape{ 1.0f }; + float enableAmbientOcclusion{ 0.0f }; + float enableShadow{ 1.0f }; + float spare1{ 1.0f }; + float spare2{ 1.0f }; + Parameters() {} }; UniformBufferView _parametersBuffer; @@ -152,6 +163,10 @@ class MakeLightingModelConfig : public render::Job::Config { Q_PROPERTY(bool enableSkinning MEMBER enableSkinning NOTIFY dirty) Q_PROPERTY(bool enableBlendshape MEMBER enableBlendshape NOTIFY dirty) + Q_PROPERTY(bool enableAmbientOcclusion MEMBER enableAmbientOcclusion NOTIFY dirty) + Q_PROPERTY(bool enableShadow MEMBER enableShadow NOTIFY dirty) + + public: MakeLightingModelConfig() : render::Job::Config() {} // Make Lighting Model is always on @@ -181,6 +196,9 @@ public: bool enableSkinning{ true }; bool enableBlendshape{ true }; + bool enableAmbientOcclusion{ true }; + bool enableShadow{ true }; + signals: void dirty(); }; diff --git a/libraries/render-utils/src/RenderShadowTask.cpp b/libraries/render-utils/src/RenderShadowTask.cpp index 31f5084589..49782b451c 100644 --- a/libraries/render-utils/src/RenderShadowTask.cpp +++ b/libraries/render-utils/src/RenderShadowTask.cpp @@ -39,7 +39,7 @@ using namespace render; extern void initZPassPipelines(ShapePlumber& plumber, gpu::StatePointer state, const render::ShapePipeline::BatchSetter& batchSetter, const render::ShapePipeline::ItemSetter& itemSetter); void RenderShadowTask::configure(const Config& configuration) { - DependencyManager::get()->setShadowMapEnabled(configuration.isEnabled()); + //DependencyManager::get()->setShadowMapEnabled(configuration.isEnabled()); // This is a task, so must still propogate configure() to its Jobs // Task::configure(configuration); } @@ -112,7 +112,7 @@ void RenderShadowTask::build(JobModel& task, const render::Varying& input, rende // GPU jobs: Render to shadow map sprintf(jobName, "RenderShadowMap%d", i); const auto shadowInputs = RenderShadowMap::Inputs(culledShadowItemsAndBounds.getN(0), - culledShadowItemsAndBounds.getN(1), lightFrame).asVarying(); + culledShadowItemsAndBounds.getN(1), shadowFrame).asVarying(); task.addJob(jobName, shadowInputs, shapePlumber, i); sprintf(jobName, "ShadowCascadeTeardown%d", i); task.addJob(jobName, shadowFilter); @@ -214,12 +214,12 @@ void RenderShadowMap::run(const render::RenderContextPointer& renderContext, con const auto& inShapes = inputs.get0(); const auto& inShapeBounds = inputs.get1(); - const auto& lightFrame = inputs.get2(); + const auto& shadowFrame = inputs.get2(); - auto lightStage = renderContext->_scene->getStage(); - assert(lightStage); - - auto shadow = lightStage->getCurrentKeyShadow(*lightFrame); + LightStage::ShadowPointer shadow; + if (shadowFrame && !shadowFrame->_objects.empty()) { + shadow = shadowFrame->_objects.front(); + } if (!shadow || _cascadeIndex >= shadow->getCascadeCount()) { return; } @@ -362,13 +362,15 @@ void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, c // Clear previous shadow frame if (!_globalShadowObject) { - _globalShadowObject = std::make_shared(graphics::LightPointer(), 100.0f); + _globalShadowObject = std::make_shared(graphics::LightPointer(), 100.f, 4); } _shadowFrameCache->_objects.clear(); - const auto theGlobalShadow = lightStage->getCurrentKeyShadow(lightFrame); - if (theGlobalShadow) { - _globalShadowObject->setLight(theGlobalShadow->getLight()); + const auto theGlobalLight = lightStage->getCurrentKeyLight(lightFrame); + if (theGlobalLight && theGlobalLight->getCastShadows()) { + //const auto theGlobalShadow = lightStage->getCurrentKeyShadow(lightFrame); + //if (theGlobalShadow) { + _globalShadowObject->setLight(theGlobalLight); _globalShadowObject->setKeylightFrustum(args->getViewFrustum(), SHADOW_FRUSTUM_NEAR, SHADOW_FRUSTUM_FAR); auto& firstCascade = _globalShadowObject->getCascade(0); diff --git a/libraries/render-utils/src/RenderShadowTask.h b/libraries/render-utils/src/RenderShadowTask.h index 1ac5f27087..2af221ea52 100644 --- a/libraries/render-utils/src/RenderShadowTask.h +++ b/libraries/render-utils/src/RenderShadowTask.h @@ -25,7 +25,7 @@ class ViewFrustum; class RenderShadowMap { public: - using Inputs = render::VaryingSet3; + using Inputs = render::VaryingSet3; using JobModel = render::Job::ModelI; RenderShadowMap(render::ShapePlumberPointer shapePlumber, unsigned int cascadeIndex) : _shapePlumber{ shapePlumber }, _cascadeIndex{ cascadeIndex } {} diff --git a/scripts/developer/utilities/render/deferredLighting.qml b/scripts/developer/utilities/render/deferredLighting.qml index 78edf7939f..3316749991 100644 --- a/scripts/developer/utilities/render/deferredLighting.qml +++ b/scripts/developer/utilities/render/deferredLighting.qml @@ -93,7 +93,9 @@ Rectangle { "Spot:LightingModel:enableSpotLight", "Light Contour:LightingModel:showLightContour", "Zone Stack:DrawZoneStack:enabled", - "Shadow:RenderShadowTask:enabled" + "Shadow:RenderShadowTask:enabled", + "Shadowning:LightingModel:enableShadow", + "AmbientOcclusioning:LightingModel:enableAmbientOcclusion" ] HifiControls.CheckBox { boxSize: 20 From 237fb4dc4cf726b625dfe917dbd6c19ce433e3b1 Mon Sep 17 00:00:00 2001 From: sam gateau Date: Mon, 17 Dec 2018 17:34:47 -0800 Subject: [PATCH 22/31] Shadows are completely working with settings on both pipeline --- interface/resources/config/render.json | 14 -- interface/src/Menu.cpp | 24 +++- .../src/AmbientOcclusionEffect.cpp | 17 ++- .../render-utils/src/AmbientOcclusionEffect.h | 9 +- .../src/DeferredLightingEffect.cpp | 9 +- .../render-utils/src/DeferredLightingEffect.h | 14 +- libraries/render-utils/src/LightingModel.h | 12 +- .../render-utils/src/RenderDeferredTask.cpp | 19 +-- .../render-utils/src/RenderDeferredTask.h | 4 +- .../render-utils/src/RenderForwardTask.cpp | 5 +- .../render-utils/src/RenderForwardTask.h | 2 +- .../render-utils/src/RenderShadowTask.cpp | 34 +++-- libraries/render-utils/src/RenderShadowTask.h | 19 +-- libraries/render-utils/src/RenderViewTask.cpp | 17 +-- .../utilities/render/deferredLighting.qml | 8 +- .../developer/utilities/render/engineList.js | 13 ++ .../developer/utilities/render/engineList.qml | 30 ++++ scripts/developer/utilities/render/holo.js | 130 ++++++++++++++++++ 18 files changed, 284 insertions(+), 96 deletions(-) create mode 100644 scripts/developer/utilities/render/engineList.js create mode 100644 scripts/developer/utilities/render/engineList.qml create mode 100644 scripts/developer/utilities/render/holo.js diff --git a/interface/resources/config/render.json b/interface/resources/config/render.json index b5b72d7d07..2c63c08510 100644 --- a/interface/resources/config/render.json +++ b/interface/resources/config/render.json @@ -1,16 +1,2 @@ { - "RenderMainView": { - "RenderShadowTask": { - "Enabled": { - "enabled": true - } - }, - "RenderDeferredTask": { - "AmbientOcclusion": { - "Enabled": { - "enabled": true - } - } - } - } } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index a3c854d883..14106278cd 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -48,6 +48,7 @@ #include "DeferredLightingEffect.h" #include "PickManager.h" +#include "LightingModel.h" #include "AmbientOcclusionEffect.h" #include "RenderShadowTask.h" #include "AntialiasingEffect.h" @@ -393,14 +394,19 @@ Menu::Menu() { connect(action, &QAction::triggered, [action] { auto renderConfig = qApp->getRenderEngine()->getConfiguration(); if (renderConfig) { - auto mainViewShadowTaskConfig = renderConfig->getConfig("RenderMainView.RenderShadowTask"); + auto lightingModelConfig = renderConfig->getConfig("RenderMainView.LightingModel"); + if (lightingModelConfig) { + lightingModelConfig->setShadow(action->isChecked()); + } + + /* auto mainViewShadowTaskConfig = renderConfig->getConfig("RenderMainView.RenderShadowTask"); if (mainViewShadowTaskConfig) { if (action->isChecked()) { mainViewShadowTaskConfig->setPreset("Enabled"); } else { mainViewShadowTaskConfig->setPreset("None"); } - } + }*/ } }); @@ -408,14 +414,24 @@ Menu::Menu() { connect(action, &QAction::triggered, [action] { auto renderConfig = qApp->getRenderEngine()->getConfiguration(); if (renderConfig) { - auto mainViewAmbientOcclusionConfig = renderConfig->getConfig("RenderMainView.AmbientOcclusion"); + auto lightingModelConfig = renderConfig->getConfig("RenderMainView.LightingModel"); + if (lightingModelConfig) { + lightingModelConfig->setAmbientOcclusion(action->isChecked()); + /* if (action->isChecked()) { + lightingModelConfig->setPreset("Enabled"); + } + else { + mainViewAmbientOcclusionConfig->setPreset("None"); + }*/ + } + /* auto mainViewAmbientOcclusionConfig = renderConfig->getConfig("RenderMainView.AmbientOcclusion"); if (mainViewAmbientOcclusionConfig) { if (action->isChecked()) { mainViewAmbientOcclusionConfig->setPreset("Enabled"); } else { mainViewAmbientOcclusionConfig->setPreset("None"); } - } + }*/ } }); diff --git a/libraries/render-utils/src/AmbientOcclusionEffect.cpp b/libraries/render-utils/src/AmbientOcclusionEffect.cpp index c8f6831376..b1ca24de1f 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.cpp +++ b/libraries/render-utils/src/AmbientOcclusionEffect.cpp @@ -589,14 +589,21 @@ void AmbientOcclusionEffect::updateJitterSamples() { } } -void AmbientOcclusionEffect::run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs) { +void AmbientOcclusionEffect::run(const render::RenderContextPointer& renderContext, const Input& input, Output& output) { assert(renderContext->args); assert(renderContext->args->hasViewFrustum()); RenderArgs* args = renderContext->args; - const auto& frameTransform = inputs.get0(); - const auto& linearDepthFramebuffer = inputs.get2(); + const auto& lightingModel = input.get0(); + + if (!lightingModel->isAmbientOcclusionEnabled()) { + output.edit0().reset(); + return; + } + + const auto& frameTransform = input.get1(); + const auto& linearDepthFramebuffer = input.get3(); const int resolutionLevel = _aoParametersBuffer->getResolutionLevel(); const auto depthResolutionLevel = getDepthResolutionLevel(); @@ -629,8 +636,8 @@ void AmbientOcclusionEffect::run(const render::RenderContextPointer& renderConte auto occlusionFBO = _framebuffer->getOcclusionFramebuffer(); auto occlusionBlurredFBO = _framebuffer->getOcclusionBlurredFramebuffer(); - outputs.edit0() = _framebuffer; - outputs.edit1() = _aoParametersBuffer; + output.edit0() = _framebuffer; + output.edit1() = _aoParametersBuffer; auto occlusionPipeline = getOcclusionPipeline(); auto bilateralBlurPipeline = getBilateralBlurPipeline(); diff --git a/libraries/render-utils/src/AmbientOcclusionEffect.h b/libraries/render-utils/src/AmbientOcclusionEffect.h index af6f6b21a3..65fc09a814 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.h +++ b/libraries/render-utils/src/AmbientOcclusionEffect.h @@ -17,6 +17,7 @@ #include "render/DrawTask.h" +#include "LightingModel.h" #include "DeferredFrameTransform.h" #include "DeferredFramebuffer.h" #include "SurfaceGeometryPass.h" @@ -152,15 +153,15 @@ signals: class AmbientOcclusionEffect { public: - using Inputs = render::VaryingSet3; - using Outputs = render::VaryingSet2; + using Input = render::VaryingSet4; + using Output = render::VaryingSet2; using Config = AmbientOcclusionEffectConfig; - using JobModel = render::Job::ModelIO; + using JobModel = render::Job::ModelIO; AmbientOcclusionEffect(); void configure(const Config& config); - void run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs); + void run(const render::RenderContextPointer& renderContext, const Input& input, Output& output); // Class describing the uniform buffer with all the parameters common to the AO shaders class AOParameters : public AmbientOcclusionParams { diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index bc7fdb06e7..7677d9b05f 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -378,8 +378,7 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, const HazeStage::FramePointer& hazeFrame, const SurfaceGeometryFramebufferPointer& surfaceGeometryFramebuffer, const AmbientOcclusionFramebufferPointer& ambientOcclusionFramebuffer, - const SubsurfaceScatteringResourcePointer& subsurfaceScatteringResource, - bool renderShadows) { + const SubsurfaceScatteringResourcePointer& subsurfaceScatteringResource) { auto args = renderContext->args; auto& batch = (*args->_batch); @@ -596,9 +595,7 @@ void RenderDeferredCleanup::run(const render::RenderContextPointer& renderContex } } -RenderDeferred::RenderDeferred(bool renderShadows): - _renderShadows(renderShadows) -{ +RenderDeferred::RenderDeferred() { DependencyManager::get()->init(); } @@ -629,7 +626,7 @@ void RenderDeferred::run(const RenderContextPointer& renderContext, const Inputs args->_batch = &batch; _gpuTimer->begin(batch); - setupJob.run(renderContext, deferredTransform, deferredFramebuffer, lightingModel, lightFrame, shadowFrame, hazeFrame, surfaceGeometryFramebuffer, ssaoFramebuffer, subsurfaceScatteringResource, _renderShadows); + setupJob.run(renderContext, deferredTransform, deferredFramebuffer, lightingModel, lightFrame, shadowFrame, hazeFrame, surfaceGeometryFramebuffer, ssaoFramebuffer, subsurfaceScatteringResource); lightsJob.run(renderContext, deferredTransform, deferredFramebuffer, lightingModel, surfaceGeometryFramebuffer, lightClusters); diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 1379b7dc89..cba9961389 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -55,16 +55,9 @@ public: static void setupLocalLightsBatch(gpu::Batch& batch, const LightClustersPointer& lightClusters); static void unsetLocalLightsBatch(gpu::Batch& batch); - // void setShadowMapEnabled(bool enable) { _shadowMapEnabled = enable; }; -// void setAmbientOcclusionEnabled(bool enable) { _ambientOcclusionEnabled = enable; } - // bool isAmbientOcclusionEnabled() const { return _ambientOcclusionEnabled; } - private: DeferredLightingEffect() = default; -// bool _shadowMapEnabled{ true }; // note that this value is overwritten in the ::configure method - // bool _ambientOcclusionEnabled{ false }; - graphics::MeshPointer _pointLightMesh; graphics::MeshPointer getPointLightMesh(); graphics::MeshPointer _spotLightMesh; @@ -150,8 +143,7 @@ public: const HazeStage::FramePointer& hazeFrame, const SurfaceGeometryFramebufferPointer& surfaceGeometryFramebuffer, const AmbientOcclusionFramebufferPointer& ambientOcclusionFramebuffer, - const SubsurfaceScatteringResourcePointer& subsurfaceScatteringResource, - bool renderShadows); + const SubsurfaceScatteringResourcePointer& subsurfaceScatteringResource); }; class RenderDeferredLocals { @@ -168,7 +160,6 @@ public: gpu::BufferView _localLightsBuffer; RenderDeferredLocals(); - }; @@ -190,7 +181,7 @@ public: using Config = RenderDeferredConfig; using JobModel = render::Job::ModelI; - RenderDeferred(bool renderShadows = false); + RenderDeferred(); void configure(const Config& config); @@ -204,7 +195,6 @@ protected: gpu::RangeTimerPointer _gpuTimer; private: - bool _renderShadows { false }; }; class DefaultLightingSetup { diff --git a/libraries/render-utils/src/LightingModel.h b/libraries/render-utils/src/LightingModel.h index 995c7cdfb7..571eadb60b 100644 --- a/libraries/render-utils/src/LightingModel.h +++ b/libraries/render-utils/src/LightingModel.h @@ -163,8 +163,8 @@ class MakeLightingModelConfig : public render::Job::Config { Q_PROPERTY(bool enableSkinning MEMBER enableSkinning NOTIFY dirty) Q_PROPERTY(bool enableBlendshape MEMBER enableBlendshape NOTIFY dirty) - Q_PROPERTY(bool enableAmbientOcclusion MEMBER enableAmbientOcclusion NOTIFY dirty) - Q_PROPERTY(bool enableShadow MEMBER enableShadow NOTIFY dirty) + Q_PROPERTY(bool enableAmbientOcclusion READ isAmbientOcclusionEnabled WRITE setAmbientOcclusion NOTIFY dirty) + Q_PROPERTY(bool enableShadow READ isShadowEnabled WRITE setShadow NOTIFY dirty) public: @@ -199,6 +199,14 @@ public: bool enableAmbientOcclusion{ true }; bool enableShadow{ true }; + + void setAmbientOcclusion(bool enable) { enableAmbientOcclusion = enable; emit dirty();} + bool isAmbientOcclusionEnabled() const { return enableAmbientOcclusion; } + void setShadow(bool enable) { + enableShadow = enable; emit dirty(); + } + bool isShadowEnabled() const { return enableShadow; } + signals: void dirty(); }; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 78ad5fa2d3..38bc3f0c0e 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -112,7 +112,7 @@ void RenderDeferredTask::configure(const Config& config) { upsamplePrimaryBufferConfig->setProperty("factor", 1.0f / config.resolutionScale); } -void RenderDeferredTask::build(JobModel& task, const render::Varying& input, render::Varying& output, bool renderShadows) { +void RenderDeferredTask::build(JobModel& task, const render::Varying& input, render::Varying& output) { auto fadeEffect = DependencyManager::get(); // Prepare the ShapePipelines ShapePlumberPointer shapePlumber = std::make_shared(); @@ -139,8 +139,11 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto& spatialSelection = fetchedItems.get1(); + // Lighting model comes next, the big configuration of the view + const auto& lightingModel = inputs[1]; + // Extract the Lighting Stages Current frame ( and zones) - const auto lightingStageInputs = inputs.get1(); + const auto& lightingStageInputs = inputs.get2(); // Fetch the current frame stacks from all the stages const auto currentStageFrames = lightingStageInputs.get0(); const auto lightFrame = currentStageFrames[0]; @@ -151,11 +154,12 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto& zones = lightingStageInputs[1]; // Shadow Task Outputs - const auto shadowTaskOutputs = inputs.get2(); + const auto& shadowTaskOutputs = inputs.get3(); // Shadow Stage Frame const auto shadowFrame = shadowTaskOutputs[1]; + fadeEffect->build(task, opaques); const auto jitter = task.addJob("JitterCam"); @@ -165,7 +169,6 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren // Prepare deferred, generate the shared Deferred Frame Transform. Only valid with the scaled frame buffer const auto deferredFrameTransform = task.addJob("DeferredFrameTransform", jitter); - const auto lightingModel = task.addJob("LightingModel"); const auto opaqueRangeTimer = task.addJob("BeginOpaqueRangeTimer", "DrawOpaques"); @@ -202,10 +205,10 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto scatteringResource = task.addJob("Scattering"); // AO job - const auto ambientOcclusionInputs = AmbientOcclusionEffect::Inputs(deferredFrameTransform, deferredFramebuffer, linearDepthTarget).asVarying(); + const auto ambientOcclusionInputs = AmbientOcclusionEffect::Input(lightingModel, deferredFrameTransform, deferredFramebuffer, linearDepthTarget).asVarying(); const auto ambientOcclusionOutputs = task.addJob("AmbientOcclusion", ambientOcclusionInputs); - const auto ambientOcclusionFramebuffer = ambientOcclusionOutputs.getN(0); - const auto ambientOcclusionUniforms = ambientOcclusionOutputs.getN(1); + const auto ambientOcclusionFramebuffer = ambientOcclusionOutputs.getN(0); + const auto ambientOcclusionUniforms = ambientOcclusionOutputs.getN(1); // Velocity const auto velocityBufferInputs = VelocityBufferPass::Inputs(deferredFrameTransform, deferredFramebuffer).asVarying(); @@ -220,7 +223,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren // DeferredBuffer is complete, now let's shade it into the LightingBuffer const auto deferredLightingInputs = RenderDeferred::Inputs(deferredFrameTransform, deferredFramebuffer, lightingModel, surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, scatteringResource, lightClusters, lightFrame, shadowFrame, hazeFrame).asVarying(); - task.addJob("RenderDeferred", deferredLightingInputs, renderShadows); + task.addJob("RenderDeferred", deferredLightingInputs); // Similar to light stage, background stage has been filled by several potential render items and resolved for the frame in this job const auto backgroundInputs = DrawBackgroundStage::Inputs(lightingModel, backgroundFrame).asVarying(); diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index be204ef6a5..0a188ec3a6 100644 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -137,14 +137,14 @@ signals: class RenderDeferredTask { public: - using Input = render::VaryingSet3; + using Input = render::VaryingSet4; using Config = RenderDeferredTaskConfig; using JobModel = render::Task::ModelI; RenderDeferredTask(); void configure(const Config& config); - void build(JobModel& task, const render::Varying& input, render::Varying& output, bool renderShadows); + void build(JobModel& task, const render::Varying& input, render::Varying& output); private: }; diff --git a/libraries/render-utils/src/RenderForwardTask.cpp b/libraries/render-utils/src/RenderForwardTask.cpp index 31e22f00d5..9f1f83dc20 100755 --- a/libraries/render-utils/src/RenderForwardTask.cpp +++ b/libraries/render-utils/src/RenderForwardTask.cpp @@ -54,8 +54,10 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend // const auto& items = fetchedItems[0]; const auto& items = fetchedItems.get0(); + // Lighting model comes next, the big configuration of the view + const auto& lightingModel = inputs.get1(); - const auto& lightingStageInputs = inputs.get1(); + const auto& lightingStageInputs = inputs.get2(); // Fetch the current frame stacks from all the stages const auto& currentStageFrames = lightingStageInputs.get0(); const auto& lightFrame = currentStageFrames[0]; @@ -91,7 +93,6 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend // Prepare objects shared by several jobs const auto deferredFrameTransform = task.addJob("DeferredFrameTransform"); - const auto lightingModel = task.addJob("LightingModel"); // Filter zones from the general metas bucket // const auto zones = task.addJob("ZoneRenderer", metas); diff --git a/libraries/render-utils/src/RenderForwardTask.h b/libraries/render-utils/src/RenderForwardTask.h index 60d3dbd54d..e6a6008319 100755 --- a/libraries/render-utils/src/RenderForwardTask.h +++ b/libraries/render-utils/src/RenderForwardTask.h @@ -19,7 +19,7 @@ class RenderForwardTask { public: - using Input = render::VaryingSet2; + using Input = render::VaryingSet3; using JobModel = render::Task::ModelI; RenderForwardTask() {} diff --git a/libraries/render-utils/src/RenderShadowTask.cpp b/libraries/render-utils/src/RenderShadowTask.cpp index 49782b451c..7a75ae9e67 100644 --- a/libraries/render-utils/src/RenderShadowTask.cpp +++ b/libraries/render-utils/src/RenderShadowTask.cpp @@ -59,11 +59,14 @@ void RenderShadowTask::build(JobModel& task, const render::Varying& input, rende // FIXME: calling this here before the zones/lights are drawn during the deferred/forward passes means we're actually using the frames from the previous draw // Fetch the current frame stacks from all the stages // Starting with the Light Frame genreated in previous tasks - const auto& lightFrame = input; + + const auto& lightFrame = input.getN(0); - const auto setupOutput = task.addJob("ShadowSetup", lightFrame); - const auto queryResolution = setupOutput.getN(1); - const auto shadowFrame = setupOutput.getN(3); + const auto& lightingModel = input.getN(1); + + const auto setupOutput = task.addJob("ShadowSetup", input); + const auto queryResolution = setupOutput.getN(1); + const auto shadowFrame = setupOutput.getN(3); // Fetch and cull the items from the scene static const auto shadowCasterReceiverFilter = ItemFilter::Builder::visibleWorldItems().withTypeShape().withOpaque().withoutLayered().withTagBits(tagBits, tagMask); @@ -75,7 +78,7 @@ void RenderShadowTask::build(JobModel& task, const render::Varying& input, rende // Cull objects that are not visible in camera view. Hopefully the cull functor only performs LOD culling, not // frustum culling or this will make shadow casters out of the camera frustum disappear. - const auto cameraFrustum = setupOutput.getN(2); + const auto cameraFrustum = setupOutput.getN(2); const auto applyFunctorInputs = ApplyCullFunctorOnItemBounds::Inputs(shadowItems, cameraFrustum).asVarying(); const auto culledShadowItems = task.addJob("ShadowCullCamera", applyFunctorInputs, cameraCullFunctor); @@ -122,7 +125,7 @@ void RenderShadowTask::build(JobModel& task, const render::Varying& input, rende task.addJob("ShadowTeardown", setupOutput); - output = Output(cascadeSceneBBoxes, setupOutput.getN(3)); + output = Output(cascadeSceneBBoxes, setupOutput.getN(3)); } @@ -341,12 +344,19 @@ void RenderShadowSetup::setSlopeBias(int cascadeIndex, float value) { _bias[cascadeIndex]._slope = value * value * value * 0.01f; } -void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, const Inputs& input, Outputs& output) { +void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, const Input& input, Output& output) { // Abort all jobs if not casting shadows auto lightStage = renderContext->_scene->getStage(); - auto lightFrame = *input; assert(lightStage); - if (!lightStage->getCurrentKeyLight(lightFrame) || !lightStage->getCurrentKeyLight(lightFrame)->getCastShadows()) { + + const auto lightFrame = *input.get0(); + const auto lightingModel = input.get1(); + + // Clear previous shadow frame always + _shadowFrameCache->_objects.clear(); + output.edit3() = _shadowFrameCache; + + if (!lightingModel->isShadowEnabled() || !lightStage->getCurrentKeyLight(lightFrame) || !lightStage->getCurrentKeyLight(lightFrame)->getCastShadows()) { renderContext->taskFlow.abortTask(); return; } @@ -360,16 +370,12 @@ void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, c *_cameraFrustum = args->getViewFrustum(); output.edit2() = _cameraFrustum; - // Clear previous shadow frame if (!_globalShadowObject) { _globalShadowObject = std::make_shared(graphics::LightPointer(), 100.f, 4); } - _shadowFrameCache->_objects.clear(); const auto theGlobalLight = lightStage->getCurrentKeyLight(lightFrame); if (theGlobalLight && theGlobalLight->getCastShadows()) { - //const auto theGlobalShadow = lightStage->getCurrentKeyShadow(lightFrame); - //if (theGlobalShadow) { _globalShadowObject->setLight(theGlobalLight); _globalShadowObject->setKeylightFrustum(args->getViewFrustum(), SHADOW_FRUSTUM_NEAR, SHADOW_FRUSTUM_FAR); @@ -435,8 +441,6 @@ void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, c queryResolution.x = int(queryResolution.x * _coarseShadowFrustum->getWidth() / firstCascadeFrustum->getWidth()); queryResolution.y = int(queryResolution.y * _coarseShadowFrustum->getHeight() / firstCascadeFrustum->getHeight()); output.edit1() = queryResolution; - - output.edit3() = _shadowFrameCache; } } diff --git a/libraries/render-utils/src/RenderShadowTask.h b/libraries/render-utils/src/RenderShadowTask.h index 2af221ea52..271c3e8200 100644 --- a/libraries/render-utils/src/RenderShadowTask.h +++ b/libraries/render-utils/src/RenderShadowTask.h @@ -19,6 +19,7 @@ #include "Shadows_shared.slh" +#include "LightingModel.h" #include "LightStage.h" class ViewFrustum; @@ -36,10 +37,12 @@ protected: unsigned int _cascadeIndex; }; -class RenderShadowTaskConfig : public render::Task::Config::Persistent { +//class RenderShadowTaskConfig : public render::Task::Config::Persistent { +class RenderShadowTaskConfig : public render::Task::Config { Q_OBJECT public: - RenderShadowTaskConfig() : render::Task::Config::Persistent(QStringList() << "Render" << "Engine" << "Shadows", true) {} + // RenderShadowTaskConfig() : render::Task::Config::Persistent(QStringList() << "Render" << "Engine" << "Shadows", true) {} + RenderShadowTaskConfig() {} signals: void dirty(); @@ -49,7 +52,7 @@ class RenderShadowTask { public: // There is one AABox per shadow cascade - using Input = LightStage::FramePointer; + using Input = render::VaryingSet2; using Output = render::VaryingSet2, LightStage::ShadowFramePointer>; using Config = RenderShadowTaskConfig; using JobModel = render::Task::ModelIO; @@ -100,14 +103,14 @@ signals: class RenderShadowSetup { public: - using Inputs = LightStage::FramePointer; - using Outputs = render::VaryingSet4; + using Input = RenderShadowTask::Input; + using Output = render::VaryingSet4; using Config = RenderShadowSetupConfig; - using JobModel = render::Job::ModelIO; + using JobModel = render::Job::ModelIO; RenderShadowSetup(); void configure(const Config& configuration); - void run(const render::RenderContextPointer& renderContext, const Inputs& input, Outputs& output); + void run(const render::RenderContextPointer& renderContext, const Input& input, Output& output); private: @@ -151,7 +154,7 @@ public: class RenderShadowTeardown { public: - using Input = RenderShadowSetup::Outputs; + using Input = RenderShadowSetup::Output; using JobModel = render::Job::ModelI; void run(const render::RenderContextPointer& renderContext, const Input& input); }; diff --git a/libraries/render-utils/src/RenderViewTask.cpp b/libraries/render-utils/src/RenderViewTask.cpp index 082a77b996..7230635060 100644 --- a/libraries/render-utils/src/RenderViewTask.cpp +++ b/libraries/render-utils/src/RenderViewTask.cpp @@ -16,24 +16,25 @@ #include "RenderForwardTask.h" void RenderViewTask::build(JobModel& task, const render::Varying& input, render::Varying& output, render::CullFunctor cullFunctor, bool isDeferred, uint8_t tagBits, uint8_t tagMask) { - // auto items = input.get(); - const auto items = task.addJob("FetchCullSort", cullFunctor, tagBits, tagMask); assert(items.canCast()); - // const auto lightingStageFramesAndZones = task.addJob("AssembleStages", items[0]); + // Issue the lighting model, aka the big global settings for the view + const auto lightingModel = task.addJob("LightingModel"); + + // Assemble the lighting stages current frames const auto lightingStageFramesAndZones = task.addJob("AssembleStages", items); if (isDeferred) { // Warning : the cull functor passed to the shadow pass should only be testing for LOD culling. If frustum culling // is performed, then casters not in the view frustum will be removed, which is not what we wish. - const auto& ligthStageFrame = lightingStageFramesAndZones.get().get0()[0]; - const auto cascadeSceneBBoxes = task.addJob("RenderShadowTask", ligthStageFrame, cullFunctor, tagBits, tagMask); + const auto shadowTaskIn = RenderShadowTask::Input(lightingStageFramesAndZones.get().get0()[0], lightingModel).asVarying(); + const auto shadowTaskOut = task.addJob("RenderShadowTask", shadowTaskIn, cullFunctor, tagBits, tagMask); - const auto renderInput = RenderDeferredTask::Input(items, lightingStageFramesAndZones, cascadeSceneBBoxes).asVarying(); - task.addJob("RenderDeferredTask", renderInput, true); + const auto renderInput = RenderDeferredTask::Input(items, lightingModel, lightingStageFramesAndZones, shadowTaskOut).asVarying(); + task.addJob("RenderDeferredTask", renderInput); } else { - const auto renderInput = RenderForwardTask::Input(items, lightingStageFramesAndZones).asVarying(); + const auto renderInput = RenderForwardTask::Input(items, lightingModel, lightingStageFramesAndZones).asVarying(); task.addJob("Forward", renderInput); } } diff --git a/scripts/developer/utilities/render/deferredLighting.qml b/scripts/developer/utilities/render/deferredLighting.qml index 3316749991..9737fb7f1a 100644 --- a/scripts/developer/utilities/render/deferredLighting.qml +++ b/scripts/developer/utilities/render/deferredLighting.qml @@ -47,8 +47,8 @@ Rectangle { "Emissive:LightingModel:enableEmissive", "Lightmap:LightingModel:enableLightmap", "Background:LightingModel:enableBackground", - "Haze:LightingModel:enableHaze", - "ssao:AmbientOcclusion:enabled", + "Haze:LightingModel:enableHaze", + "ssao:LightingModel:enableAmbientOcclusion", "Textures:LightingModel:enableMaterialTexturing" ] HifiControls.CheckBox { @@ -93,9 +93,7 @@ Rectangle { "Spot:LightingModel:enableSpotLight", "Light Contour:LightingModel:showLightContour", "Zone Stack:DrawZoneStack:enabled", - "Shadow:RenderShadowTask:enabled", - "Shadowning:LightingModel:enableShadow", - "AmbientOcclusioning:LightingModel:enableAmbientOcclusion" + "Shadow:LightingModel:enableShadow" ] HifiControls.CheckBox { boxSize: 20 diff --git a/scripts/developer/utilities/render/engineList.js b/scripts/developer/utilities/render/engineList.js new file mode 100644 index 0000000000..85028ded53 --- /dev/null +++ b/scripts/developer/utilities/render/engineList.js @@ -0,0 +1,13 @@ + function openEngineTaskView() { + // Set up the qml ui + var qml = Script.resolvePath('engineList.qml'); + var window = new OverlayWindow({ + title: 'Render Engine', + source: qml, + width: 300, + height: 400 + }); + window.setPosition(200, 50); + //window.closed.connect(function() { Script.stop(); }); + } + openEngineTaskView(); \ No newline at end of file diff --git a/scripts/developer/utilities/render/engineList.qml b/scripts/developer/utilities/render/engineList.qml new file mode 100644 index 0000000000..bf5c2a13a8 --- /dev/null +++ b/scripts/developer/utilities/render/engineList.qml @@ -0,0 +1,30 @@ +// +// engineList.qml +// +// Created by Sam Gateau on 12/3/2018 +// Copyright 2018 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html +// +import QtQuick 2.7 +import QtQuick.Controls 1.4 +import QtQuick.Layouts 1.3 + +import stylesUit 1.0 +import controlsUit 1.0 as HifiControls + +import "../lib/jet/qml" as Jet + +Item { + HifiConstants { id: hifi;} + id: render; + anchors.fill: parent + + property var mainViewTask: Render.getConfig("RenderMainView") + + Jet.TaskList { + rootConfig: Render + anchors.fill: render + } +} \ No newline at end of file diff --git a/scripts/developer/utilities/render/holo.js b/scripts/developer/utilities/render/holo.js new file mode 100644 index 0000000000..401e601b66 --- /dev/null +++ b/scripts/developer/utilities/render/holo.js @@ -0,0 +1,130 @@ +"use strict"; +// +// holo.js +// +// Created by Sam Gateau on 2018-12-17 +// Copyright 2018 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0 +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +(function() { + // Function Name: inFrontOf() + // + // Description: + // -Returns the position in front of the given "position" argument, where the forward vector is based off + // the "orientation" argument and the amount in front is based off the "distance" argument. + function inFrontOf(distance, position, orientation) { + return Vec3.sum(position || MyAvatar.position, + Vec3.multiply(distance, Quat.getForward(orientation || MyAvatar.orientation))); + } + + //***************************************************** + // Holo + //***************************************************** + + function Holo(config) { + this.baseEntityProperties = { + name: "Holo-base", + //"collisionless": false, + "color": { + "blue": 239, + "green": 180, + "red": 0 + }, + "dimensions": { + "x": 10, + "y": 0.1, + "z": 10, + }, + "grab": { + "grabbable": false, + }, + // "ignoreForCollisions": false, + type: "Shape", + shape: "Cylinder", + shapeType:"box", + "position": inFrontOf(8, Vec3.sum(MyAvatar.position, { x: 0, y: -1, z: 0 })), + "rotation": Quat.multiply(MyAvatar.orientation, { w: 0, x: 0, y: 1, z: 0 }), + lifetime: config.lifetime, + } + this.baseEntity = Entities.addEntity( this.baseEntityProperties ); + this.baseEntityProperties = Entities.getEntityProperties(this.baseEntity); + + this.screenEntityProperties = { + name: "Holo-screen", + "collisionless": true, + "color": { + "blue": 239, + "red": 180, + "green": 0 + }, + "dimensions": { + "x": 5, + "y": 0.1, + "z": 5, + }, + "grab": { + "grabbable": false, + }, + "ignoreForCollisions": true, + type: "Shape", + shape: "Cylinder", + "position": inFrontOf(8, Vec3.sum(MyAvatar.position, { x: 0, y: -0.9, z: 0 })), + "rotation": Quat.multiply(MyAvatar.orientation, { w: 0, x: 0, y: 1, z: 0 }), + lifetime: config.lifetime, + } + this.screenEntity = Entities.addEntity( this.screenEntityProperties ); + this.screenEntityProperties = Entities.getEntityProperties(this.screenEntity); + + var DIM = {x: 5.0, y: 5.0, z: 0.0}; + + this.screen = Overlays.addOverlay("image3d", { + url: "resource://spectatorCameraFrame", + emissive: true, + parentID: this.screenEntity, + alpha: 1, + localRotation: { w: 1, x: 0, y: 0, z: 0 }, + localPosition: { x: 0, y: 4.0, z: 0.0 }, + dimensions: DIM, + lifetime: config.lifetime, + }); + } + + Holo.prototype.kill = function () { + if (this.baseEntity) { + Entities.deleteEntity(this.baseEntity); + // this.entity = null + } + if (this.screenEntity) { + Entities.deleteEntity(this.screenEntity); + // this.entity = null + } + if (this.screen) { + Overlays.deleteOverlay(this.view); + } + }; + + + //***************************************************** + // Exe + //***************************************************** + + var holo; + + function shutdown() { + if (holo) { + holo.kill(); + } + + } + + function startup() { + holo = new Holo({ lifetime: 60}); + } + + startup(); + Script.scriptEnding.connect(shutdown); +}()); \ No newline at end of file From 76f204b5aa7171deaabe0526c3074a362e936470 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 18 Dec 2018 00:45:12 -0800 Subject: [PATCH 23/31] Exploring the hologram --- scripts/developer/utilities/render/holo.js | 69 +++++++++++++++++----- 1 file changed, 55 insertions(+), 14 deletions(-) diff --git a/scripts/developer/utilities/render/holo.js b/scripts/developer/utilities/render/holo.js index 401e601b66..a19a80c66e 100644 --- a/scripts/developer/utilities/render/holo.js +++ b/scripts/developer/utilities/render/holo.js @@ -24,7 +24,8 @@ //***************************************************** // Holo //***************************************************** - + const SECONDARY_CAMERA_RESOLUTION = 1024; // width/height multiplier, in pixels + function Holo(config) { this.baseEntityProperties = { name: "Holo-base", @@ -47,50 +48,86 @@ shape: "Cylinder", shapeType:"box", "position": inFrontOf(8, Vec3.sum(MyAvatar.position, { x: 0, y: -1, z: 0 })), - "rotation": Quat.multiply(MyAvatar.orientation, { w: 0, x: 0, y: 1, z: 0 }), + "rotation": MyAvatar.orientation, lifetime: config.lifetime, } this.baseEntity = Entities.addEntity( this.baseEntityProperties ); this.baseEntityProperties = Entities.getEntityProperties(this.baseEntity); + var DIM = {x: 6.0, y: 3.0, z: 0.0}; + this.screenEntityProperties = { name: "Holo-screen", + "visible": false, "collisionless": true, "color": { "blue": 239, "red": 180, "green": 0 }, - "dimensions": { - "x": 5, - "y": 0.1, - "z": 5, - }, + "dimensions": DIM, "grab": { "grabbable": false, }, "ignoreForCollisions": true, type: "Shape", - shape: "Cylinder", - "position": inFrontOf(8, Vec3.sum(MyAvatar.position, { x: 0, y: -0.9, z: 0 })), - "rotation": Quat.multiply(MyAvatar.orientation, { w: 0, x: 0, y: 1, z: 0 }), + shape: "Box", + parentID: this.baseEntity, + localPosition: { x: 0, y: DIM.y * 0.5, z: 0 }, + localRotation: { w: 1, x: 0, y: 0, z: 0 }, lifetime: config.lifetime, } this.screenEntity = Entities.addEntity( this.screenEntityProperties ); this.screenEntityProperties = Entities.getEntityProperties(this.screenEntity); - var DIM = {x: 5.0, y: 5.0, z: 0.0}; + this.screenOutEntityProperties = { + name: "Holo-screen-out", + "visible": false, + "collisionless": true, + "color": { + "blue": 239, + "red": 180, + "green": 0 + }, + "dimensions": DIM, + "grab": { + "grabbable": false, + }, + "ignoreForCollisions": true, + type: "Shape", + shape: "Box", + parentID: this.screenEntity, + // localRotation: { w: 0, x: 0, y: 1, z: 0 }, + lifetime: config.lifetime, + } + this.screenOutEntity = Entities.addEntity( this.screenOutEntityProperties ); + this.screenOutEntityProperties = Entities.getEntityProperties(this.screenOutEntity); + + + var spectatorCameraConfig = Render.getConfig("SecondaryCamera"); + Render.getConfig("SecondaryCameraJob.ToneMapping").curve = 0; + spectatorCameraConfig.enableSecondaryCameraRenderConfigs(true); + spectatorCameraConfig.portalProjection = true; + spectatorCameraConfig.portalEntranceEntityId = this.screenOutEntity; + spectatorCameraConfig.attachedEntityId = this.screenEntity; + + spectatorCameraConfig.resetSizeSpectatorCamera(DIM.x * SECONDARY_CAMERA_RESOLUTION, + DIM.y * SECONDARY_CAMERA_RESOLUTION); this.screen = Overlays.addOverlay("image3d", { url: "resource://spectatorCameraFrame", emissive: true, parentID: this.screenEntity, alpha: 1, localRotation: { w: 1, x: 0, y: 0, z: 0 }, - localPosition: { x: 0, y: 4.0, z: 0.0 }, - dimensions: DIM, + localPosition: { x: 0, y: 0.0, z: 0.0 }, + dimensions: { + x: (DIM.y > DIM.x ? DIM.y : DIM.x), + y: -(DIM.y > DIM.x ? DIM.y : DIM.x), + z: 0 + }, lifetime: config.lifetime, - }); + }); } Holo.prototype.kill = function () { @@ -102,6 +139,10 @@ Entities.deleteEntity(this.screenEntity); // this.entity = null } + if (this.screenOutEntity) { + Entities.deleteEntity(this.screenOutEntity); + // this.entity = null + } if (this.screen) { Overlays.deleteOverlay(this.view); } From d8e7305f4a12140b0a21c6652144e12133513219 Mon Sep 17 00:00:00 2001 From: sam gateau Date: Tue, 18 Dec 2018 09:16:40 -0800 Subject: [PATCH 24/31] Removing hili for now --- scripts/developer/utilities/render/holo.js | 171 --------------------- 1 file changed, 171 deletions(-) delete mode 100644 scripts/developer/utilities/render/holo.js diff --git a/scripts/developer/utilities/render/holo.js b/scripts/developer/utilities/render/holo.js deleted file mode 100644 index a19a80c66e..0000000000 --- a/scripts/developer/utilities/render/holo.js +++ /dev/null @@ -1,171 +0,0 @@ -"use strict"; -// -// holo.js -// -// Created by Sam Gateau on 2018-12-17 -// Copyright 2018 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0 -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - - -(function() { - // Function Name: inFrontOf() - // - // Description: - // -Returns the position in front of the given "position" argument, where the forward vector is based off - // the "orientation" argument and the amount in front is based off the "distance" argument. - function inFrontOf(distance, position, orientation) { - return Vec3.sum(position || MyAvatar.position, - Vec3.multiply(distance, Quat.getForward(orientation || MyAvatar.orientation))); - } - - //***************************************************** - // Holo - //***************************************************** - const SECONDARY_CAMERA_RESOLUTION = 1024; // width/height multiplier, in pixels - - function Holo(config) { - this.baseEntityProperties = { - name: "Holo-base", - //"collisionless": false, - "color": { - "blue": 239, - "green": 180, - "red": 0 - }, - "dimensions": { - "x": 10, - "y": 0.1, - "z": 10, - }, - "grab": { - "grabbable": false, - }, - // "ignoreForCollisions": false, - type: "Shape", - shape: "Cylinder", - shapeType:"box", - "position": inFrontOf(8, Vec3.sum(MyAvatar.position, { x: 0, y: -1, z: 0 })), - "rotation": MyAvatar.orientation, - lifetime: config.lifetime, - } - this.baseEntity = Entities.addEntity( this.baseEntityProperties ); - this.baseEntityProperties = Entities.getEntityProperties(this.baseEntity); - - var DIM = {x: 6.0, y: 3.0, z: 0.0}; - - this.screenEntityProperties = { - name: "Holo-screen", - "visible": false, - "collisionless": true, - "color": { - "blue": 239, - "red": 180, - "green": 0 - }, - "dimensions": DIM, - "grab": { - "grabbable": false, - }, - "ignoreForCollisions": true, - type: "Shape", - shape: "Box", - parentID: this.baseEntity, - localPosition: { x: 0, y: DIM.y * 0.5, z: 0 }, - localRotation: { w: 1, x: 0, y: 0, z: 0 }, - lifetime: config.lifetime, - } - this.screenEntity = Entities.addEntity( this.screenEntityProperties ); - this.screenEntityProperties = Entities.getEntityProperties(this.screenEntity); - - this.screenOutEntityProperties = { - name: "Holo-screen-out", - "visible": false, - "collisionless": true, - "color": { - "blue": 239, - "red": 180, - "green": 0 - }, - "dimensions": DIM, - "grab": { - "grabbable": false, - }, - "ignoreForCollisions": true, - type: "Shape", - shape: "Box", - parentID: this.screenEntity, - // localRotation: { w: 0, x: 0, y: 1, z: 0 }, - lifetime: config.lifetime, - } - this.screenOutEntity = Entities.addEntity( this.screenOutEntityProperties ); - this.screenOutEntityProperties = Entities.getEntityProperties(this.screenOutEntity); - - - - var spectatorCameraConfig = Render.getConfig("SecondaryCamera"); - Render.getConfig("SecondaryCameraJob.ToneMapping").curve = 0; - spectatorCameraConfig.enableSecondaryCameraRenderConfigs(true); - spectatorCameraConfig.portalProjection = true; - spectatorCameraConfig.portalEntranceEntityId = this.screenOutEntity; - spectatorCameraConfig.attachedEntityId = this.screenEntity; - - spectatorCameraConfig.resetSizeSpectatorCamera(DIM.x * SECONDARY_CAMERA_RESOLUTION, - DIM.y * SECONDARY_CAMERA_RESOLUTION); - this.screen = Overlays.addOverlay("image3d", { - url: "resource://spectatorCameraFrame", - emissive: true, - parentID: this.screenEntity, - alpha: 1, - localRotation: { w: 1, x: 0, y: 0, z: 0 }, - localPosition: { x: 0, y: 0.0, z: 0.0 }, - dimensions: { - x: (DIM.y > DIM.x ? DIM.y : DIM.x), - y: -(DIM.y > DIM.x ? DIM.y : DIM.x), - z: 0 - }, - lifetime: config.lifetime, - }); - } - - Holo.prototype.kill = function () { - if (this.baseEntity) { - Entities.deleteEntity(this.baseEntity); - // this.entity = null - } - if (this.screenEntity) { - Entities.deleteEntity(this.screenEntity); - // this.entity = null - } - if (this.screenOutEntity) { - Entities.deleteEntity(this.screenOutEntity); - // this.entity = null - } - if (this.screen) { - Overlays.deleteOverlay(this.view); - } - }; - - - //***************************************************** - // Exe - //***************************************************** - - var holo; - - function shutdown() { - if (holo) { - holo.kill(); - } - - } - - function startup() { - holo = new Holo({ lifetime: 60}); - } - - startup(); - Script.scriptEnding.connect(shutdown); -}()); \ No newline at end of file From 2f18555ee06f07d1b40d32368106527549f5f9fb Mon Sep 17 00:00:00 2001 From: sam gateau Date: Tue, 18 Dec 2018 14:42:45 -0800 Subject: [PATCH 25/31] removing comments and dead code, rewiring the debug --- interface/src/Menu.cpp | 25 +----- interface/src/SecondaryCamera.cpp | 17 +--- .../src/RenderableZoneEntityItem.cpp | 2 - .../src/RenderableZoneEntityItem.h | 1 - .../src/AssembleLightingStageTask.cpp | 5 -- .../src/AssembleLightingStageTask.h | 1 - .../src/DeferredLightingEffect.cpp | 21 ++--- .../render-utils/src/DeferredLightingEffect.h | 6 +- .../render-utils/src/RenderDeferredTask.cpp | 87 +++++++++---------- .../render-utils/src/RenderForwardTask.cpp | 79 ++++++++--------- 10 files changed, 94 insertions(+), 150 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 14106278cd..140d2a7ccc 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -398,15 +398,6 @@ Menu::Menu() { if (lightingModelConfig) { lightingModelConfig->setShadow(action->isChecked()); } - - /* auto mainViewShadowTaskConfig = renderConfig->getConfig("RenderMainView.RenderShadowTask"); - if (mainViewShadowTaskConfig) { - if (action->isChecked()) { - mainViewShadowTaskConfig->setPreset("Enabled"); - } else { - mainViewShadowTaskConfig->setPreset("None"); - } - }*/ } }); @@ -417,22 +408,8 @@ Menu::Menu() { auto lightingModelConfig = renderConfig->getConfig("RenderMainView.LightingModel"); if (lightingModelConfig) { lightingModelConfig->setAmbientOcclusion(action->isChecked()); - /* if (action->isChecked()) { - lightingModelConfig->setPreset("Enabled"); - } - else { - mainViewAmbientOcclusionConfig->setPreset("None"); - }*/ } - /* auto mainViewAmbientOcclusionConfig = renderConfig->getConfig("RenderMainView.AmbientOcclusion"); - if (mainViewAmbientOcclusionConfig) { - if (action->isChecked()) { - mainViewAmbientOcclusionConfig->setPreset("Enabled"); - } else { - mainViewAmbientOcclusionConfig->setPreset("None"); - } - }*/ - } + } }); addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::WorldAxes); diff --git a/interface/src/SecondaryCamera.cpp b/interface/src/SecondaryCamera.cpp index f8b656e627..12c9636746 100644 --- a/interface/src/SecondaryCamera.cpp +++ b/interface/src/SecondaryCamera.cpp @@ -272,22 +272,7 @@ public: void SecondaryCameraRenderTask::build(JobModel& task, const render::Varying& inputs, render::Varying& outputs, render::CullFunctor cullFunctor, bool isDeferred) { const auto cachedArg = task.addJob("SecondaryCamera"); - task.addJob("RenderSecondView", cullFunctor, true, render::ItemKey::TAG_BITS_1, render::ItemKey::TAG_BITS_1); -/* - const auto items = task.addJob("FetchCullSort", cullFunctor, render::ItemKey::TAG_BITS_1, render::ItemKey::TAG_BITS_1); - assert(items.canCast()); + task.addJob("RenderSecondView", cullFunctor, isDeferred, render::ItemKey::TAG_BITS_1, render::ItemKey::TAG_BITS_1); - // const auto lightingStageFramesAndZones = task.addJob("AssembleStages", items[0]); - const auto lightingStageFramesAndZones = task.addJob("AssembleStages", items); - - if (isDeferred) { - const render::Varying cascadeSceneBBoxes; - const auto renderInput = RenderDeferredTask::Input(items, lightingStageFramesAndZones, cascadeSceneBBoxes).asVarying(); - task.addJob("RenderDeferredTask", renderInput, false); - } else { - const auto renderInput = RenderForwardTask::Input(items, lightingStageFramesAndZones).asVarying(); - task.addJob("Forward", renderInput); - } -*/ task.addJob("EndSecondaryCamera", cachedArg); } \ No newline at end of file diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index 0986f35d8d..7c6e583ef4 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -43,7 +43,6 @@ void ZoneEntityRenderer::onRemoveFromSceneTyped(const TypedEntityPointer& entity if (!LightStage::isIndexInvalid(_sunIndex)) { _stage->removeLight(_sunIndex); _sunIndex = INVALID_INDEX; - _shadowIndex = INVALID_INDEX; } if (!LightStage::isIndexInvalid(_ambientIndex)) { _stage->removeLight(_ambientIndex); @@ -100,7 +99,6 @@ void ZoneEntityRenderer::doRender(RenderArgs* args) { // Do we need to allocate the light in the stage ? if (LightStage::isIndexInvalid(_sunIndex)) { _sunIndex = _stage->addLight(_sunLight); - // _shadowIndex = _stage->addShadow(_sunIndex, SUN_SHADOW_MAX_DISTANCE, SUN_SHADOW_CASCADE_COUNT); } else { _stage->updateLightArrayBuffer(_sunIndex); } diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.h b/libraries/entities-renderer/src/RenderableZoneEntityItem.h index 3e2690e1bd..32b5cf94a0 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.h +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.h @@ -99,7 +99,6 @@ private: ComponentMode _bloomMode { COMPONENT_MODE_INHERIT }; indexed_container::Index _sunIndex { LightStage::INVALID_INDEX }; - indexed_container::Index _shadowIndex { LightStage::INVALID_INDEX }; indexed_container::Index _ambientIndex { LightStage::INVALID_INDEX }; BackgroundStagePointer _backgroundStage; diff --git a/libraries/render-utils/src/AssembleLightingStageTask.cpp b/libraries/render-utils/src/AssembleLightingStageTask.cpp index ff9eaa195e..589cdb31ea 100644 --- a/libraries/render-utils/src/AssembleLightingStageTask.cpp +++ b/libraries/render-utils/src/AssembleLightingStageTask.cpp @@ -45,11 +45,6 @@ void AssembleLightingStageTask::build(JobModel& task, const render::Varying& inp // Fetch the current frame stacks from all the stages const auto currentStageFrames = task.addJob("FetchCurrentFrames"); - /* const auto lightFrame = currentStageFrames.getN(0); - const auto backgroundFrame = currentStageFrames.getN(1); - const auto hazeFrame = currentStageFrames.getN(2); - const auto bloomFrame = currentStageFrames.getN(3); -*/ output = Output(currentStageFrames, zones); } diff --git a/libraries/render-utils/src/AssembleLightingStageTask.h b/libraries/render-utils/src/AssembleLightingStageTask.h index c32d5f9a30..9770af473c 100644 --- a/libraries/render-utils/src/AssembleLightingStageTask.h +++ b/libraries/render-utils/src/AssembleLightingStageTask.h @@ -32,7 +32,6 @@ public: class AssembleLightingStageTask { public: - // using Input = RenderFetchCullSortTask::BucketList; using Input = RenderFetchCullSortTask::Output; using Output = render::VaryingSet2; using JobModel = render::Task::ModelIO; diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 7677d9b05f..ab9dea2325 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -603,19 +603,21 @@ void RenderDeferred::configure(const Config& config) { } void RenderDeferred::run(const RenderContextPointer& renderContext, const Inputs& inputs) { + auto args = renderContext->args; auto deferredTransform = inputs.get0(); auto deferredFramebuffer = inputs.get1(); - auto lightingModel = inputs.get2(); - auto surfaceGeometryFramebuffer = inputs.get3(); - auto ssaoFramebuffer = inputs.get4(); - auto subsurfaceScatteringResource = inputs.get5(); - auto lightClusters = inputs.get6(); - auto args = renderContext->args; + auto extraRenderBuffers = inputs.get2(); + auto surfaceGeometryFramebuffer = extraRenderBuffers.get0(); + auto ssaoFramebuffer = extraRenderBuffers.get1(); + auto subsurfaceScatteringResource = extraRenderBuffers.get2(); - const auto& lightFrame = inputs.get7(); - const auto& shadowFrame = inputs.get8(); - const auto& hazeFrame = inputs.get9(); + auto lightingModel = inputs.get3(); + auto lightClusters = inputs.get4(); + + const auto& lightFrame = inputs.get5(); + const auto& shadowFrame = inputs.get6(); + const auto& hazeFrame = inputs.get7(); if (!_gpuTimer) { _gpuTimer = std::make_shared < gpu::RangeTimer>(__FUNCTION__); @@ -684,7 +686,6 @@ void DefaultLightingSetup::run(const RenderContextPointer& renderContext) { // Add the global light to the light stage (for later shadow rendering) // Set this light to be the default _defaultLightID = lightStage->addLight(lp, true); - // lightStage->addShadow(_defaultLightID); } auto backgroundStage = renderContext->_scene->getStage(); diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index cba9961389..f4935000ef 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -174,9 +174,9 @@ using RenderDeferredConfig = render::GPUJobConfig; class RenderDeferred { public: - using Inputs = render::VaryingSet10< - DeferredFrameTransformPointer, DeferredFramebufferPointer, LightingModelPointer, SurfaceGeometryFramebufferPointer, - AmbientOcclusionFramebufferPointer, SubsurfaceScatteringResourcePointer, LightClustersPointer, LightStage::FramePointer, LightStage::ShadowFramePointer, HazeStage::FramePointer>; + using ExtraDeferredBuffer = render::VaryingSet3; + using Inputs = render::VaryingSet8< + DeferredFrameTransformPointer, DeferredFramebufferPointer, ExtraDeferredBuffer, LightingModelPointer, LightClustersPointer, LightStage::FramePointer, LightStage::ShadowFramePointer, HazeStage::FramePointer>; using Config = RenderDeferredConfig; using JobModel = render::Job::ModelI; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 38bc3f0c0e..2d2015658a 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -72,28 +72,19 @@ namespace gr { } -/* -class RenderDeferredTaskDebugConfig : public render::Task::Config { - -public: - - signals : - void dirty(); -};*/ - class RenderDeferredTaskDebug { public: + using ExtraBuffers = render::VaryingSet5; using Input = render::VaryingSet9; - // using Config = RenderDeferredTaskConfig; + AssembleLightingStageTask::Output, LightClusteringPass::Output, + PrepareDeferred::Outputs, ExtraBuffers, GenerateDeferredFrameTransform::Output, + JitterSample::Output, LightingModel>; + using JobModel = render::Task::ModelI; RenderDeferredTaskDebug(); - // void configure(const Config& config); void build(JobModel& task, const render::Varying& inputs, render::Varying& outputs); - private: }; @@ -221,8 +212,8 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto lightClusters = task.addJob("LightClustering", lightClusteringPassInputs); // DeferredBuffer is complete, now let's shade it into the LightingBuffer - const auto deferredLightingInputs = RenderDeferred::Inputs(deferredFrameTransform, deferredFramebuffer, lightingModel, - surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, scatteringResource, lightClusters, lightFrame, shadowFrame, hazeFrame).asVarying(); + const auto extraDeferredBuffer = RenderDeferred::ExtraDeferredBuffer(surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, scatteringResource).asVarying(); + const auto deferredLightingInputs = RenderDeferred::Inputs(deferredFrameTransform, deferredFramebuffer, extraDeferredBuffer, lightingModel, lightClusters, lightFrame, shadowFrame, hazeFrame).asVarying(); task.addJob("RenderDeferred", deferredLightingInputs); // Similar to light stage, background stage has been filled by several potential render items and resolved for the frame in this job @@ -265,7 +256,9 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren // Debugging task is happening in the "over" layer after tone mapping and just before HUD { // Debug the bounds of the rendered items, still look at the zbuffer - const auto debugInputs = RenderDeferredTaskDebug::Input(fetchedItems, inputs.get2(), lightingStageInputs, lightClusters, linearDepthTarget, prepareDeferredOutputs, deferredFrameTransform, jitter, lightingModel).asVarying(); + const auto extraDebugBuffers = RenderDeferredTaskDebug::ExtraBuffers(linearDepthTarget, surfaceGeometryFramebuffer, ambientOcclusionOutputs, scatteringResource, velocityBuffer); + const auto debugInputs = RenderDeferredTaskDebug::Input(fetchedItems, inputs.get2(), lightingStageInputs, lightClusters, prepareDeferredOutputs, extraDebugBuffers, + deferredFrameTransform, jitter, lightingModel).asVarying(); task.addJob("DebugRenderDeferredTask", debugInputs); } @@ -289,10 +282,6 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren RenderDeferredTaskDebug::RenderDeferredTaskDebug() { } -/* -void RenderDeferredTaskDebug::configure(const Config& config) { - -}*/ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input, render::Varying& outputs) { @@ -300,20 +289,21 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input // RenderFetchCullSortTask out const auto& fetchCullSortTaskOut = inputs.get0(); - const auto& items = fetchCullSortTaskOut.get0(); - const auto& spatialSelection = fetchCullSortTaskOut[1]; + const auto& items = fetchCullSortTaskOut.get0(); - // Extract opaques / transparents / lights / metas / overlays InFront and HUD / background - const auto& opaques = items[RenderFetchCullSortTask::OPAQUE_SHAPE]; - const auto& transparents = items[RenderFetchCullSortTask::TRANSPARENT_SHAPE]; - const auto& lights = items[RenderFetchCullSortTask::LIGHT]; - const auto& metas = items[RenderFetchCullSortTask::META]; - const auto& overlayOpaques = items[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; - const auto& overlayTransparents = items[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; - const auto& overlaysInFrontOpaque = items[RenderFetchCullSortTask::LAYER_FRONT_OPAQUE_SHAPE]; - const auto& overlaysInFrontTransparent = items[RenderFetchCullSortTask::LAYER_FRONT_TRANSPARENT_SHAPE]; - const auto& overlaysHUDOpaque = items[RenderFetchCullSortTask::LAYER_HUD_OPAQUE_SHAPE]; - const auto& overlaysHUDTransparent = items[RenderFetchCullSortTask::LAYER_HUD_TRANSPARENT_SHAPE]; + // Extract opaques / transparents / lights / metas / overlays InFront and HUD / background + const auto& opaques = items[RenderFetchCullSortTask::OPAQUE_SHAPE]; + const auto& transparents = items[RenderFetchCullSortTask::TRANSPARENT_SHAPE]; + const auto& lights = items[RenderFetchCullSortTask::LIGHT]; + const auto& metas = items[RenderFetchCullSortTask::META]; + const auto& overlayOpaques = items[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; + const auto& overlayTransparents = items[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; + const auto& overlaysInFrontOpaque = items[RenderFetchCullSortTask::LAYER_FRONT_OPAQUE_SHAPE]; + const auto& overlaysInFrontTransparent = items[RenderFetchCullSortTask::LAYER_FRONT_TRANSPARENT_SHAPE]; + const auto& overlaysHUDOpaque = items[RenderFetchCullSortTask::LAYER_HUD_OPAQUE_SHAPE]; + const auto& overlaysHUDTransparent = items[RenderFetchCullSortTask::LAYER_HUD_TRANSPARENT_SHAPE]; + + const auto& spatialSelection = fetchCullSortTaskOut[1]; // RenderShadowTask out const auto& shadowOut = inputs.get1(); @@ -324,10 +314,10 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input const auto lightingStageInputs = inputs.get2(); // Fetch the current frame stacks from all the stages const auto stageCurrentFrames = lightingStageInputs.get0(); - const auto lightFrame = stageCurrentFrames[0]; - const auto backgroundFrame = stageCurrentFrames[1]; - const auto hazeFrame = stageCurrentFrames[2]; - const auto bloomFrame = stageCurrentFrames[3]; + const auto lightFrame = stageCurrentFrames[0]; + const auto backgroundFrame = stageCurrentFrames[1]; + const auto hazeFrame = stageCurrentFrames[2]; + const auto bloomFrame = stageCurrentFrames[3]; // Zones const auto& zones = lightingStageInputs[1]; @@ -335,11 +325,19 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input // Light CLuster const auto& lightClusters = inputs[3]; - // linear Depth Target - const auto& linearDepthTarget = inputs[4]; - // PrepareDeferred out - const auto& deferredFramebuffer = inputs[5]; + const auto& prepareDeferredOutputs = inputs.get4(); + const auto& deferredFramebuffer = prepareDeferredOutputs[0]; + + // extraDeferredBuffer + const auto& extraDeferredBuffer = inputs.get5(); + const auto& linearDepthTarget = extraDeferredBuffer.get0(); + const auto& surfaceGeometryFramebuffer = extraDeferredBuffer.get1(); + const auto& ambientOcclusionOut = extraDeferredBuffer.get2(); + const auto& ambientOcclusionFramebuffer = ambientOcclusionOut[0]; + const auto& ambientOcclusionUniforms = ambientOcclusionOut[1]; + const auto& scatteringResource = extraDeferredBuffer[3]; + const auto& velocityBuffer = extraDeferredBuffer[4]; // GenerateDeferredFrameTransform out const auto& deferredFrameTransform = inputs[6]; @@ -412,8 +410,9 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input // Debugging stages { + // Debugging Deferred buffer job - /* const auto debugFramebuffers = render::Varying(DebugDeferredBuffer::Inputs(deferredFramebuffer, linearDepthTarget, surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, velocityBuffer, deferredFrameTransform, lightFrame)); + const auto debugFramebuffers = DebugDeferredBuffer::Inputs(deferredFramebuffer, linearDepthTarget, surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, velocityBuffer, deferredFrameTransform, lightFrame).asVarying(); task.addJob("DebugDeferredBuffer", debugFramebuffers); const auto debugSubsurfaceScatteringInputs = DebugSubsurfaceScattering::Inputs(deferredFrameTransform, deferredFramebuffer, lightingModel, @@ -422,7 +421,7 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input const auto debugAmbientOcclusionInputs = DebugAmbientOcclusion::Inputs(deferredFrameTransform, deferredFramebuffer, linearDepthTarget, ambientOcclusionUniforms).asVarying(); task.addJob("DebugAmbientOcclusion", debugAmbientOcclusionInputs); -*/ + // Scene Octree Debugging job { task.addJob("DrawSceneOctree", spatialSelection); diff --git a/libraries/render-utils/src/RenderForwardTask.cpp b/libraries/render-utils/src/RenderForwardTask.cpp index 9f1f83dc20..7c266a32f5 100755 --- a/libraries/render-utils/src/RenderForwardTask.cpp +++ b/libraries/render-utils/src/RenderForwardTask.cpp @@ -48,62 +48,53 @@ using namespace render; extern void initForwardPipelines(ShapePlumber& plumber); void RenderForwardTask::build(JobModel& task, const render::Varying& input, render::Varying& output) { - const auto& inputs = input.get(); - const auto& fetchedItems = inputs.get0(); - // const auto& fetchedItems = inputs[0]; - // const auto& items = fetchedItems[0]; - const auto& items = fetchedItems.get0(); - - // Lighting model comes next, the big configuration of the view - const auto& lightingModel = inputs.get1(); - - const auto& lightingStageInputs = inputs.get2(); - // Fetch the current frame stacks from all the stages - const auto& currentStageFrames = lightingStageInputs.get0(); - const auto& lightFrame = currentStageFrames[0]; - const auto& backgroundFrame = currentStageFrames[1]; - const auto& hazeFrame = currentStageFrames[2]; - const auto& bloomFrame = currentStageFrames[3]; - - const auto& zones = lightingStageInputs[1]; - - - auto fadeEffect = DependencyManager::get(); - // Prepare the ShapePipelines + auto fadeEffect = DependencyManager::get(); ShapePlumberPointer shapePlumber = std::make_shared(); initForwardPipelines(*shapePlumber); - // Extract opaques / transparents / lights / metas / overlays / background - const auto& opaques = items[RenderFetchCullSortTask::OPAQUE_SHAPE]; - const auto& transparents = items[RenderFetchCullSortTask::TRANSPARENT_SHAPE]; - const auto& lights = items[RenderFetchCullSortTask::LIGHT]; - const auto& metas = items[RenderFetchCullSortTask::META]; - const auto& overlayOpaques = items[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; - const auto& overlayTransparents = items[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; - const auto& overlaysInFrontOpaque = items[RenderFetchCullSortTask::LAYER_FRONT_OPAQUE_SHAPE]; - const auto& overlaysInFrontTransparent = items[RenderFetchCullSortTask::LAYER_FRONT_TRANSPARENT_SHAPE]; - const auto& overlaysHUDOpaque = items[RenderFetchCullSortTask::LAYER_HUD_OPAQUE_SHAPE]; - const auto& overlaysHUDTransparent = items[RenderFetchCullSortTask::LAYER_HUD_TRANSPARENT_SHAPE]; + // Unpack inputs + const auto& inputs = input.get(); + + // Separate the fetched items + const auto& fetchedItems = inputs.get0(); - const auto& spatialSelection = fetchedItems[1]; + const auto& items = fetchedItems.get0(); + // Extract opaques / transparents / lights / metas / overlays / background + const auto& opaques = items[RenderFetchCullSortTask::OPAQUE_SHAPE]; + const auto& transparents = items[RenderFetchCullSortTask::TRANSPARENT_SHAPE]; + const auto& lights = items[RenderFetchCullSortTask::LIGHT]; + const auto& metas = items[RenderFetchCullSortTask::META]; + const auto& overlayOpaques = items[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; + const auto& overlayTransparents = items[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; + const auto& overlaysInFrontOpaque = items[RenderFetchCullSortTask::LAYER_FRONT_OPAQUE_SHAPE]; + const auto& overlaysInFrontTransparent = items[RenderFetchCullSortTask::LAYER_FRONT_TRANSPARENT_SHAPE]; + const auto& overlaysHUDOpaque = items[RenderFetchCullSortTask::LAYER_HUD_OPAQUE_SHAPE]; + const auto& overlaysHUDTransparent = items[RenderFetchCullSortTask::LAYER_HUD_TRANSPARENT_SHAPE]; + const auto& spatialSelection = fetchedItems.get1(); + + // Lighting model comes next, the big configuration of the view + const auto& lightingModel = inputs[1]; + + // Extract the Lighting Stages Current frame ( and zones) + const auto& lightingStageInputs = inputs.get2(); + // Fetch the current frame stacks from all the stages + const auto currentStageFrames = lightingStageInputs.get0(); + const auto lightFrame = currentStageFrames[0]; + const auto backgroundFrame = currentStageFrames[1]; + const auto& hazeFrame = currentStageFrames[2]; + const auto& bloomFrame = currentStageFrames[3]; + + const auto& zones = lightingStageInputs[1]; + + // First job, alter faded fadeEffect->build(task, opaques); // Prepare objects shared by several jobs const auto deferredFrameTransform = task.addJob("DeferredFrameTransform"); - // Filter zones from the general metas bucket - // const auto zones = task.addJob("ZoneRenderer", metas); - - // Fetch the current frame stacks from all the stages - // const auto currentFrames = task.addJob("FetchCurrentFrames"); - // const auto lightFrame = currentFrames.getN(0); - // const auto backgroundFrame = currentFrames.getN(1); - //const auto hazeFrame = currentFrames.getN(2); - //const auto bloomFrame = currentFrames.getN(3); - // GPU jobs: Start preparing the main framebuffer const auto framebuffer = task.addJob("PrepareFramebuffer"); From 5b50b0332d7590cfe85c19fbfd968a00a6f59a20 Mon Sep 17 00:00:00 2001 From: sam gateau Date: Tue, 18 Dec 2018 15:30:45 -0800 Subject: [PATCH 26/31] more fixes --- .../render-utils/src/RenderDeferredTask.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 2d2015658a..595d22e816 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -74,7 +74,7 @@ namespace gr { class RenderDeferredTaskDebug { public: - using ExtraBuffers = render::VaryingSet5; + using ExtraBuffers = render::VaryingSet6; using Input = render::VaryingSet9("DebugRenderDeferredTask", debugInputs); @@ -331,13 +331,12 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input // extraDeferredBuffer const auto& extraDeferredBuffer = inputs.get5(); - const auto& linearDepthTarget = extraDeferredBuffer.get0(); - const auto& surfaceGeometryFramebuffer = extraDeferredBuffer.get1(); - const auto& ambientOcclusionOut = extraDeferredBuffer.get2(); - const auto& ambientOcclusionFramebuffer = ambientOcclusionOut[0]; - const auto& ambientOcclusionUniforms = ambientOcclusionOut[1]; - const auto& scatteringResource = extraDeferredBuffer[3]; - const auto& velocityBuffer = extraDeferredBuffer[4]; + const auto& linearDepthTarget = extraDeferredBuffer[0]; + const auto& surfaceGeometryFramebuffer = extraDeferredBuffer[1]; + const auto& ambientOcclusionFramebuffer = extraDeferredBuffer[2]; + const auto& ambientOcclusionUniforms = extraDeferredBuffer[3]; + const auto& scatteringResource = extraDeferredBuffer[4]; + const auto& velocityBuffer = extraDeferredBuffer[5]; // GenerateDeferredFrameTransform out const auto& deferredFrameTransform = inputs[6]; From b8d96d98b821f7961eb6e5fae68dfd00a09cf362 Mon Sep 17 00:00:00 2001 From: sam gateau Date: Tue, 18 Dec 2018 16:25:24 -0800 Subject: [PATCH 27/31] fixing warnings from the build --- .../src/RenderableZoneEntityItem.cpp | 2 -- .../render-utils/src/RenderDeferredTask.cpp | 12 +----------- libraries/render-utils/src/RenderForwardTask.cpp | 14 ++++---------- libraries/render-utils/src/RenderShadowTask.cpp | 16 +++++----------- libraries/task/src/task/Varying.h | 2 +- 5 files changed, 11 insertions(+), 35 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index 7c6e583ef4..232e6efa67 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -27,8 +27,6 @@ // Sphere entities should fit inside a cube entity of the same size, so a sphere that has dimensions 1x1x1 // is a half unit sphere. However, the geometry cache renders a UNIT sphere, so we need to scale down. static const float SPHERE_ENTITY_SCALE = 0.5f; -static const unsigned int SUN_SHADOW_CASCADE_COUNT{ 4 }; -static const float SUN_SHADOW_MAX_DISTANCE{ 40.0f }; using namespace render; using namespace render::entities; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 595d22e816..d9bc802adc 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -119,17 +119,11 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren // Extract opaques / transparents / lights / metas / overlays / background const auto& opaques = items[RenderFetchCullSortTask::OPAQUE_SHAPE]; const auto& transparents = items[RenderFetchCullSortTask::TRANSPARENT_SHAPE]; - const auto& lights = items[RenderFetchCullSortTask::LIGHT]; - const auto& metas = items[RenderFetchCullSortTask::META]; - const auto& overlayOpaques = items[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; - const auto& overlayTransparents = items[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; const auto& overlaysInFrontOpaque = items[RenderFetchCullSortTask::LAYER_FRONT_OPAQUE_SHAPE]; const auto& overlaysInFrontTransparent = items[RenderFetchCullSortTask::LAYER_FRONT_TRANSPARENT_SHAPE]; const auto& overlaysHUDOpaque = items[RenderFetchCullSortTask::LAYER_HUD_OPAQUE_SHAPE]; const auto& overlaysHUDTransparent = items[RenderFetchCullSortTask::LAYER_HUD_TRANSPARENT_SHAPE]; - const auto& spatialSelection = fetchedItems.get1(); - // Lighting model comes next, the big configuration of the view const auto& lightingModel = inputs[1]; @@ -142,8 +136,6 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto& hazeFrame = currentStageFrames[2]; const auto& bloomFrame = currentStageFrames[3]; - const auto& zones = lightingStageInputs[1]; - // Shadow Task Outputs const auto& shadowTaskOutputs = inputs.get3(); @@ -296,8 +288,6 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input const auto& transparents = items[RenderFetchCullSortTask::TRANSPARENT_SHAPE]; const auto& lights = items[RenderFetchCullSortTask::LIGHT]; const auto& metas = items[RenderFetchCullSortTask::META]; - const auto& overlayOpaques = items[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; - const auto& overlayTransparents = items[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; const auto& overlaysInFrontOpaque = items[RenderFetchCullSortTask::LAYER_FRONT_OPAQUE_SHAPE]; const auto& overlaysInFrontTransparent = items[RenderFetchCullSortTask::LAYER_FRONT_TRANSPARENT_SHAPE]; const auto& overlaysHUDOpaque = items[RenderFetchCullSortTask::LAYER_HUD_OPAQUE_SHAPE]; @@ -308,7 +298,7 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input // RenderShadowTask out const auto& shadowOut = inputs.get1(); - const auto& renderShadowTaskOut = inputs[0]; + const auto& renderShadowTaskOut = shadowOut[0]; // Extract the Lighting Stages Current frame ( and zones) const auto lightingStageInputs = inputs.get2(); diff --git a/libraries/render-utils/src/RenderForwardTask.cpp b/libraries/render-utils/src/RenderForwardTask.cpp index 7c266a32f5..ffdbc1c4b1 100755 --- a/libraries/render-utils/src/RenderForwardTask.cpp +++ b/libraries/render-utils/src/RenderForwardTask.cpp @@ -64,16 +64,12 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend // Extract opaques / transparents / lights / metas / overlays / background const auto& opaques = items[RenderFetchCullSortTask::OPAQUE_SHAPE]; const auto& transparents = items[RenderFetchCullSortTask::TRANSPARENT_SHAPE]; - const auto& lights = items[RenderFetchCullSortTask::LIGHT]; const auto& metas = items[RenderFetchCullSortTask::META]; - const auto& overlayOpaques = items[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE]; - const auto& overlayTransparents = items[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE]; const auto& overlaysInFrontOpaque = items[RenderFetchCullSortTask::LAYER_FRONT_OPAQUE_SHAPE]; const auto& overlaysInFrontTransparent = items[RenderFetchCullSortTask::LAYER_FRONT_TRANSPARENT_SHAPE]; - const auto& overlaysHUDOpaque = items[RenderFetchCullSortTask::LAYER_HUD_OPAQUE_SHAPE]; - const auto& overlaysHUDTransparent = items[RenderFetchCullSortTask::LAYER_HUD_TRANSPARENT_SHAPE]; - - const auto& spatialSelection = fetchedItems.get1(); + // TODO: Re enable the rendering of the HUD overlayes + // const auto& overlaysHUDOpaque = items[RenderFetchCullSortTask::LAYER_HUD_OPAQUE_SHAPE]; + // const auto& overlaysHUDTransparent = items[RenderFetchCullSortTask::LAYER_HUD_TRANSPARENT_SHAPE]; // Lighting model comes next, the big configuration of the view const auto& lightingModel = inputs[1]; @@ -84,9 +80,7 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend const auto currentStageFrames = lightingStageInputs.get0(); const auto lightFrame = currentStageFrames[0]; const auto backgroundFrame = currentStageFrames[1]; - const auto& hazeFrame = currentStageFrames[2]; - const auto& bloomFrame = currentStageFrames[3]; - + const auto& zones = lightingStageInputs[1]; // First job, alter faded diff --git a/libraries/render-utils/src/RenderShadowTask.cpp b/libraries/render-utils/src/RenderShadowTask.cpp index 7a75ae9e67..bfa6f5e5d1 100644 --- a/libraries/render-utils/src/RenderShadowTask.cpp +++ b/libraries/render-utils/src/RenderShadowTask.cpp @@ -33,6 +33,8 @@ // but are readjusted afterwards #define SHADOW_FRUSTUM_NEAR 1.0f #define SHADOW_FRUSTUM_FAR 500.0f +static const unsigned int SHADOW_CASCADE_COUNT{ 4 }; +static const float SHADOW_MAX_DISTANCE{ 40.0f }; using namespace render; @@ -62,8 +64,6 @@ void RenderShadowTask::build(JobModel& task, const render::Varying& input, rende const auto& lightFrame = input.getN(0); - const auto& lightingModel = input.getN(1); - const auto setupOutput = task.addJob("ShadowSetup", input); const auto queryResolution = setupOutput.getN(1); const auto shadowFrame = setupOutput.getN(3); @@ -371,7 +371,7 @@ void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, c output.edit2() = _cameraFrustum; if (!_globalShadowObject) { - _globalShadowObject = std::make_shared(graphics::LightPointer(), 100.f, 4); + _globalShadowObject = std::make_shared(graphics::LightPointer(), SHADOW_MAX_DISTANCE, SHADOW_CASCADE_COUNT); } const auto theGlobalLight = lightStage->getCurrentKeyLight(lightFrame); @@ -446,19 +446,13 @@ void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, c void RenderShadowCascadeSetup::run(const render::RenderContextPointer& renderContext, const Inputs& input, Outputs& output) { const auto shadowFrame = input; - /* - auto lightStage = renderContext->_scene->getStage(); - const auto& lightFrame = *input; - assert(lightStage); -*/ + // Cache old render args RenderArgs* args = renderContext->args; RenderShadowTask::CullFunctor cullFunctor; - - if (shadowFrame && !shadowFrame->_objects.empty() && shadowFrame->_objects[0]) { - const auto globalShadow = shadowFrame->_objects[0]; //lightStage->getCurrentKeyShadow(lightFrame); + const auto globalShadow = shadowFrame->_objects[0]; if (globalShadow && _cascadeIndex < globalShadow->getCascadeCount()) { // Second item filter is to filter items to keep in shadow frustum computation (here we need to keep shadow receivers) diff --git a/libraries/task/src/task/Varying.h b/libraries/task/src/task/Varying.h index 18edf35937..686a00446b 100644 --- a/libraries/task/src/task/Varying.h +++ b/libraries/task/src/task/Varying.h @@ -35,7 +35,7 @@ public: template const T& get() const { return std::static_pointer_cast>(_concept)->_data; } template T& edit() { return std::static_pointer_cast>(_concept)->_data; } - const std::string& name() const { return _concept->name(); } + const std::string name() const { return _concept->name(); } // access potential sub varyings contained in this one. Varying operator[] (uint8_t index) const { return (*_concept)[index]; } From 253a71a20c287feeb2fb67d9287c3e46916337bc Mon Sep 17 00:00:00 2001 From: sam gateau Date: Wed, 19 Dec 2018 18:22:01 -0800 Subject: [PATCH 28/31] updating some code and probably broken in this version --- libraries/render-utils/src/LightStage.h | 24 +------------------ .../render-utils/src/RenderDeferredTask.cpp | 2 +- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/libraries/render-utils/src/LightStage.h b/libraries/render-utils/src/LightStage.h index 6c84859164..1fb1754862 100644 --- a/libraries/render-utils/src/LightStage.h +++ b/libraries/render-utils/src/LightStage.h @@ -118,15 +118,12 @@ public: }; using ShadowPointer = std::shared_ptr; - using Shadows = render::indexed_container::IndexedPointerVector; Index findLight(const LightPointer& light) const; Index addLight(const LightPointer& light, const bool shouldSetAsDefault = false); Index getDefaultLight() { return _defaultLightId; } - Index addShadow(Index lightIndex, float maxDistance = 20.0f, unsigned int cascadeCount = 1U); - LightPointer removeLight(Index index); bool checkLightId(Index index) const { return _lights.checkIndex(index); } @@ -135,23 +132,7 @@ public: Index getNumFreeLights() const { return _lights.getNumFreeIndices(); } Index getNumAllocatedLights() const { return _lights.getNumAllocatedIndices(); } - LightPointer getLight(Index lightId) const { - return _lights.get(lightId); - } - - Index getShadowId(Index lightId) const; - - ShadowPointer getShadow(Index lightId) const { - return _shadows.get(getShadowId(lightId)); - } - - using LightAndShadow = std::pair; - LightAndShadow getLightAndShadow(Index lightId) const { - auto light = getLight(lightId); - auto shadow = getShadow(lightId); - assert(shadow == nullptr || shadow->getLight() == light); - return LightAndShadow(light, shadow); - } + LightPointer getLight(Index lightId) const { return _lights.get(lightId); } LightStage(); @@ -211,8 +192,6 @@ public: LightPointer getCurrentKeyLight(const LightStage::Frame& frame) const; LightPointer getCurrentAmbientLight(const LightStage::Frame& frame) const; - ShadowPointer getCurrentKeyShadow(const LightStage::Frame& frame) const; - LightAndShadow getCurrentKeyLightAndShadow(const LightStage::Frame& frame) const; protected: @@ -224,7 +203,6 @@ protected: gpu::BufferPointer _lightArrayBuffer; Lights _lights; - Shadows _shadows; Descs _descs; LightMap _lightMap; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index d9bc802adc..ef19cbb3ea 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -446,7 +446,7 @@ void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs& const auto& lightFrame = inputs.get2(); const auto& lightingModel = inputs.get3(); const auto& lightClusters = inputs.get4(); - const auto& shadowFrame = inputs.get5(); + // Not used yet but will be: const auto& shadowFrame = inputs.get5(); const auto jitter = inputs.get6(); auto deferredLightingEffect = DependencyManager::get(); From 80a55e2ae972b7e50cba1b34175b3d5cdb6c0e6d Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Wed, 19 Dec 2018 20:01:14 -0800 Subject: [PATCH 29/31] Compiling --- .../render-utils/src/DebugDeferredBuffer.cpp | 20 ++++---- .../render-utils/src/DebugDeferredBuffer.h | 2 +- libraries/render-utils/src/LightStage.cpp | 47 ------------------- .../render-utils/src/RenderCommonTask.cpp | 4 +- .../render-utils/src/RenderDeferredTask.cpp | 7 +-- 5 files changed, 16 insertions(+), 64 deletions(-) diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index 9bdfdbcda6..01a9c055cc 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -403,7 +403,7 @@ void DebugDeferredBuffer::run(const RenderContextPointer& renderContext, const I auto& ambientOcclusionFramebuffer = inputs.get3(); auto& velocityFramebuffer = inputs.get4(); auto& frameTransform = inputs.get5(); - auto& lightFrame = inputs.get6(); + auto& shadowFrame = inputs.get6(); gpu::doInBatch("DebugDeferredBuffer::run", args->_context, [&](gpu::Batch& batch) { batch.enableStereo(false); @@ -439,16 +439,14 @@ void DebugDeferredBuffer::run(const RenderContextPointer& renderContext, const I batch.setResourceTexture(Textures::DebugTexture0, velocityFramebuffer->getVelocityTexture()); } - auto lightStage = renderContext->_scene->getStage(); - assert(lightStage); - assert(lightStage->getNumLights() > 0); - auto lightAndShadow = lightStage->getCurrentKeyLightAndShadow(*lightFrame); - const auto& globalShadow = lightAndShadow.second; - if (globalShadow) { - batch.setResourceTexture(Textures::Shadow, globalShadow->map); - batch.setUniformBuffer(UBOs::ShadowParams, globalShadow->getBuffer()); - batch.setUniformBuffer(UBOs::DeferredFrameTransform, frameTransform->getFrameTransformBuffer()); - batch.setUniformBuffer(UBOs::DebugDeferredParams, _parameters); + if (!shadowFrame->_objects.empty()) { + const auto& globalShadow = shadowFrame->_objects[0]; + if (globalShadow) { + batch.setResourceTexture(Textures::Shadow, globalShadow->map); + batch.setUniformBuffer(UBOs::ShadowParams, globalShadow->getBuffer()); + batch.setUniformBuffer(UBOs::DeferredFrameTransform, frameTransform->getFrameTransformBuffer()); + batch.setUniformBuffer(UBOs::DebugDeferredParams, _parameters); + } } if (linearDepthTarget) { diff --git a/libraries/render-utils/src/DebugDeferredBuffer.h b/libraries/render-utils/src/DebugDeferredBuffer.h index 8afccfca13..5ff3ab28c9 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.h +++ b/libraries/render-utils/src/DebugDeferredBuffer.h @@ -46,7 +46,7 @@ public: AmbientOcclusionFramebufferPointer, VelocityFramebufferPointer, DeferredFrameTransformPointer, - LightStage::FramePointer>; + LightStage::ShadowFramePointer>; using Config = DebugDeferredBufferConfig; using JobModel = render::Job::ModelI; diff --git a/libraries/render-utils/src/LightStage.cpp b/libraries/render-utils/src/LightStage.cpp index ad3a86507e..6913949286 100644 --- a/libraries/render-utils/src/LightStage.cpp +++ b/libraries/render-utils/src/LightStage.cpp @@ -350,27 +350,9 @@ LightStage::Index LightStage::addLight(const LightPointer& light, const bool sho return lightId; } -LightStage::Index LightStage::addShadow(Index lightIndex, float maxDistance, unsigned int cascadeCount) { - auto light = getLight(lightIndex); - Index shadowId = INVALID_INDEX; - if (light) { - assert(_descs[lightIndex].shadowId == INVALID_INDEX); - shadowId = _shadows.newElement(std::make_shared(light, maxDistance, cascadeCount)); - _descs[lightIndex].shadowId = shadowId; - } - return shadowId; -} - LightStage::LightPointer LightStage::removeLight(Index index) { LightPointer removedLight = _lights.freeElement(index); if (removedLight) { - auto shadowId = _descs[index].shadowId; - // Remove shadow if one exists for this light - if (shadowId != INVALID_INDEX) { - auto removedShadow = _shadows.freeElement(shadowId); - assert(removedShadow); - assert(removedShadow->getLight() == removedLight); - } _lightMap.erase(removedLight); _descs[index] = Desc(); } @@ -394,35 +376,6 @@ LightStage::LightPointer LightStage::getCurrentAmbientLight(const LightStage::Fr return _lights.get(keyLightId); } -LightStage::ShadowPointer LightStage::getCurrentKeyShadow(const LightStage::Frame& frame) const { - Index keyLightId { _defaultLightId }; - if (!frame._sunLights.empty()) { - keyLightId = frame._sunLights.front(); - } - auto shadow = getShadow(keyLightId); - assert(shadow == nullptr || shadow->getLight() == getLight(keyLightId)); - return shadow; -} - -LightStage::LightAndShadow LightStage::getCurrentKeyLightAndShadow(const LightStage::Frame& frame) const { - Index keyLightId { _defaultLightId }; - if (!frame._sunLights.empty()) { - keyLightId = frame._sunLights.front(); - } - auto shadow = getShadow(keyLightId); - auto light = getLight(keyLightId); - assert(shadow == nullptr || shadow->getLight() == light); - return LightAndShadow(light, shadow); -} - -LightStage::Index LightStage::getShadowId(Index lightId) const { - if (checkLightId(lightId)) { - return _descs[lightId].shadowId; - } else { - return INVALID_INDEX; - } -} - void LightStage::updateLightArrayBuffer(Index lightId) { auto lightSize = sizeof(graphics::Light::LightSchema); if (!_lightArrayBuffer) { diff --git a/libraries/render-utils/src/RenderCommonTask.cpp b/libraries/render-utils/src/RenderCommonTask.cpp index 863d6f19ea..6c44810340 100644 --- a/libraries/render-utils/src/RenderCommonTask.cpp +++ b/libraries/render-utils/src/RenderCommonTask.cpp @@ -218,12 +218,12 @@ void ExtractFrustums::run(const render::RenderContextPointer& renderContext, con for (auto i = 0; i < SHADOW_CASCADE_FRUSTUM_COUNT; i++) { auto& shadowFrustum = output[SHADOW_CASCADE0_FRUSTUM+i].edit(); if (lightStage) { - auto globalShadow = lightStage->getCurrentKeyShadow(*lightFrame); + /* auto globalShadow = lightStage->getCurrentKeyShadow(*lightFrame); if (globalShadow && i<(int)globalShadow->getCascadeCount()) { auto& cascade = globalShadow->getCascade(i); shadowFrustum = cascade.getFrustum(); - } else { + } else*/ { shadowFrustum.reset(); } } else { diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index ef19cbb3ea..8851a5cfa0 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -298,7 +298,8 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input // RenderShadowTask out const auto& shadowOut = inputs.get1(); - const auto& renderShadowTaskOut = shadowOut[0]; + const auto& renderShadowTaskOut = shadowOut[0]; + const auto& shadowFrame = shadowOut[1]; // Extract the Lighting Stages Current frame ( and zones) const auto lightingStageInputs = inputs.get2(); @@ -401,7 +402,7 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input { // Debugging Deferred buffer job - const auto debugFramebuffers = DebugDeferredBuffer::Inputs(deferredFramebuffer, linearDepthTarget, surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, velocityBuffer, deferredFrameTransform, lightFrame).asVarying(); + const auto debugFramebuffers = DebugDeferredBuffer::Inputs(deferredFramebuffer, linearDepthTarget, surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, velocityBuffer, deferredFrameTransform, shadowFrame).asVarying(); task.addJob("DebugDeferredBuffer", debugFramebuffers); const auto debugSubsurfaceScatteringInputs = DebugSubsurfaceScattering::Inputs(deferredFrameTransform, deferredFramebuffer, lightingModel, @@ -446,7 +447,7 @@ void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs& const auto& lightFrame = inputs.get2(); const auto& lightingModel = inputs.get3(); const auto& lightClusters = inputs.get4(); - // Not used yet but will be: const auto& shadowFrame = inputs.get5(); + const auto& shadowFrame = inputs.get5(); const auto jitter = inputs.get6(); auto deferredLightingEffect = DependencyManager::get(); From 21577ba311071256548459d9f36cebb9fff9a101 Mon Sep 17 00:00:00 2001 From: sam gateau Date: Thu, 20 Dec 2018 09:27:15 -0800 Subject: [PATCH 30/31] fixing warnings and the debug of shadows --- .../render-utils/src/RenderCommonTask.cpp | 19 ++++++++----------- libraries/render-utils/src/RenderCommonTask.h | 2 +- .../render-utils/src/RenderDeferredTask.cpp | 4 ++-- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/libraries/render-utils/src/RenderCommonTask.cpp b/libraries/render-utils/src/RenderCommonTask.cpp index 6c44810340..40724cbf5a 100644 --- a/libraries/render-utils/src/RenderCommonTask.cpp +++ b/libraries/render-utils/src/RenderCommonTask.cpp @@ -203,7 +203,7 @@ void ExtractFrustums::run(const render::RenderContextPointer& renderContext, con RenderArgs* args = renderContext->args; - const auto& lightFrame = inputs; + const auto& shadowFrame = inputs; // Return view frustum auto& viewFrustum = output[VIEW_FRUSTUM].edit(); @@ -214,18 +214,15 @@ void ExtractFrustums::run(const render::RenderContextPointer& renderContext, con } // Return shadow frustum - auto lightStage = args->_scene->getStage(LightStage::getName()); + LightStage::ShadowPointer globalShadow; + if (shadowFrame && !shadowFrame->_objects.empty() && shadowFrame->_objects[0]) { + globalShadow = shadowFrame->_objects[0]; + } for (auto i = 0; i < SHADOW_CASCADE_FRUSTUM_COUNT; i++) { auto& shadowFrustum = output[SHADOW_CASCADE0_FRUSTUM+i].edit(); - if (lightStage) { - /* auto globalShadow = lightStage->getCurrentKeyShadow(*lightFrame); - - if (globalShadow && i<(int)globalShadow->getCascadeCount()) { - auto& cascade = globalShadow->getCascade(i); - shadowFrustum = cascade.getFrustum(); - } else*/ { - shadowFrustum.reset(); - } + if (globalShadow && i<(int)globalShadow->getCascadeCount()) { + auto& cascade = globalShadow->getCascade(i); + shadowFrustum = cascade.getFrustum(); } else { shadowFrustum.reset(); } diff --git a/libraries/render-utils/src/RenderCommonTask.h b/libraries/render-utils/src/RenderCommonTask.h index 5d4f2184a6..29f195ffff 100644 --- a/libraries/render-utils/src/RenderCommonTask.h +++ b/libraries/render-utils/src/RenderCommonTask.h @@ -106,7 +106,7 @@ public: FRUSTUM_COUNT }; - using Inputs = LightStage::FramePointer; + using Inputs = LightStage::ShadowFramePointer; using Outputs = render::VaryingArray; using JobModel = render::Job::ModelIO; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 8851a5cfa0..8dea87015a 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -354,7 +354,7 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input task.addJob("DrawLightBounds", lights); task.addJob("DrawZones", zones); - const auto frustums = task.addJob("ExtractFrustums", lightFrame); + const auto frustums = task.addJob("ExtractFrustums", shadowFrame); const auto viewFrustum = frustums.getN(ExtractFrustums::VIEW_FRUSTUM); task.addJob("DrawViewFrustum", viewFrustum, glm::vec3(0.0f, 1.0f, 0.0f)); for (auto i = 0; i < ExtractFrustums::SHADOW_CASCADE_FRUSTUM_COUNT; i++) { @@ -447,7 +447,7 @@ void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs& const auto& lightFrame = inputs.get2(); const auto& lightingModel = inputs.get3(); const auto& lightClusters = inputs.get4(); - const auto& shadowFrame = inputs.get5(); + // Not needed yet: const auto& shadowFrame = inputs.get5(); const auto jitter = inputs.get6(); auto deferredLightingEffect = DependencyManager::get(); From 7e1f75e0f34715b775a2bc7d8e5e6a499e50954c Mon Sep 17 00:00:00 2001 From: sam gateau Date: Thu, 20 Dec 2018 13:16:41 -0800 Subject: [PATCH 31/31] Fixing the debug of shadow frustum for real --- libraries/render-utils/src/RenderDeferredTask.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 8dea87015a..a685f3998e 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -249,7 +249,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren // Debugging task is happening in the "over" layer after tone mapping and just before HUD { // Debug the bounds of the rendered items, still look at the zbuffer const auto extraDebugBuffers = RenderDeferredTaskDebug::ExtraBuffers(linearDepthTarget, surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, ambientOcclusionFramebuffer, scatteringResource, velocityBuffer); - const auto debugInputs = RenderDeferredTaskDebug::Input(fetchedItems, inputs.get2(), lightingStageInputs, lightClusters, prepareDeferredOutputs, extraDebugBuffers, + const auto debugInputs = RenderDeferredTaskDebug::Input(fetchedItems, shadowTaskOutputs, lightingStageInputs, lightClusters, prepareDeferredOutputs, extraDebugBuffers, deferredFrameTransform, jitter, lightingModel).asVarying(); task.addJob("DebugRenderDeferredTask", debugInputs); }