From 3cc445ff023b2a641996cde913b1812cf95a52bf Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Tue, 7 Nov 2017 11:07:25 +0100 Subject: [PATCH] Renamed outline to highlight --- .gitignore | 1 + .../ui/overlays/ContextOverlayInterface.cpp | 2 +- .../src/{Outline.slf => Highlight.slf} | 6 +- .../src/{Outline.slh => Highlight.slh} | 24 +- ...{OutlineEffect.cpp => HighlightEffect.cpp} | 239 +++++++++--------- .../{OutlineEffect.h => HighlightEffect.h} | 112 ++++---- ...{Outline_aabox.slv => Highlight_aabox.slv} | 0 ...utline_filled.slf => Highlight_filled.slf} | 6 +- ...utline_shared.slh => Highlight_shared.slh} | 4 +- .../render-utils/src/RenderDeferredTask.cpp | 10 +- .../render-utils/src/UpdateSceneTask.cpp | 4 +- .../render/src/render/HighlightStage.cpp | 46 ++++ libraries/render/src/render/HighlightStage.h | 77 ++++++ .../{OutlineStyle.h => HighlightStyle.h} | 17 +- .../render/src/render/OutlineStyleStage.cpp | 46 ---- .../render/src/render/OutlineStyleStage.h | 77 ------ libraries/render/src/render/Scene.cpp | 58 ++--- libraries/render/src/render/Scene.h | 34 +-- .../{debugOutline.js => debugHighlight.js} | 22 +- .../render/{outline.qml => highlight.qml} | 12 +- .../HighlightPage.qml} | 6 +- .../utilities/render/highlightPage/qmldir | 1 + .../utilities/render/outlinePage/qmldir | 1 - 23 files changed, 403 insertions(+), 402 deletions(-) rename libraries/render-utils/src/{Outline.slf => Highlight.slf} (72%) rename libraries/render-utils/src/{Outline.slh => Highlight.slh} (75%) rename libraries/render-utils/src/{OutlineEffect.cpp => HighlightEffect.cpp} (63%) rename libraries/render-utils/src/{OutlineEffect.h => HighlightEffect.h} (55%) rename libraries/render-utils/src/{Outline_aabox.slv => Highlight_aabox.slv} (100%) rename libraries/render-utils/src/{Outline_filled.slf => Highlight_filled.slf} (71%) rename libraries/render-utils/src/{Outline_shared.slh => Highlight_shared.slh} (84%) create mode 100644 libraries/render/src/render/HighlightStage.cpp create mode 100644 libraries/render/src/render/HighlightStage.h rename libraries/render/src/render/{OutlineStyle.h => HighlightStyle.h} (68%) delete mode 100644 libraries/render/src/render/OutlineStyleStage.cpp delete mode 100644 libraries/render/src/render/OutlineStyleStage.h rename scripts/developer/utilities/render/{debugOutline.js => debugHighlight.js} (88%) rename scripts/developer/utilities/render/{outline.qml => highlight.qml} (88%) rename scripts/developer/utilities/render/{outlinePage/OutlinePage.qml => highlightPage/HighlightPage.qml} (96%) create mode 100644 scripts/developer/utilities/render/highlightPage/qmldir delete mode 100644 scripts/developer/utilities/render/outlinePage/qmldir diff --git a/.gitignore b/.gitignore index 072e6001da..4b6949e268 100644 --- a/.gitignore +++ b/.gitignore @@ -64,6 +64,7 @@ gvr-interface/libs/* # ignore files for various dev environments TAGS *.sw[po] +*.qmlc # ignore node files for the console node_modules diff --git a/interface/src/ui/overlays/ContextOverlayInterface.cpp b/interface/src/ui/overlays/ContextOverlayInterface.cpp index 32e4137526..6a21221a8b 100644 --- a/interface/src/ui/overlays/ContextOverlayInterface.cpp +++ b/interface/src/ui/overlays/ContextOverlayInterface.cpp @@ -88,7 +88,7 @@ ContextOverlayInterface::ContextOverlayInterface() { void ContextOverlayInterface::initializeSelectionToSceneHandler(SelectionToSceneHandler& handler, const QString& selectionName, render::Transaction& transaction) { handler.initialize(selectionName); connect(_selectionScriptingInterface.data(), &SelectionScriptingInterface::selectedItemsListChanged, &handler, &SelectionToSceneHandler::selectedItemsListChanged); - transaction.resetSelectionOutline(selectionName.toStdString()); + transaction.resetSelectionHighlight(selectionName.toStdString()); } static const uint32_t MOUSE_HW_ID = 0; diff --git a/libraries/render-utils/src/Outline.slf b/libraries/render-utils/src/Highlight.slf similarity index 72% rename from libraries/render-utils/src/Outline.slf rename to libraries/render-utils/src/Highlight.slf index 68ef870cba..bf65f92613 100644 --- a/libraries/render-utils/src/Outline.slf +++ b/libraries/render-utils/src/Highlight.slf @@ -1,5 +1,5 @@ -// Outline.slf -// Add outline effect based on two zbuffers : one containing the total scene z and another +// Highlight.slf +// Add highlight effect based on two zbuffers : one containing the total scene z and another // with the z of only the objects to be outlined. // This is the version without the fill effect inside the silhouette. // @@ -9,5 +9,5 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -<@include Outline.slh@> +<@include Highlight.slh@> <$main(0)$> diff --git a/libraries/render-utils/src/Outline.slh b/libraries/render-utils/src/Highlight.slh similarity index 75% rename from libraries/render-utils/src/Outline.slh rename to libraries/render-utils/src/Highlight.slh index aeaf20a24a..2faa10682e 100644 --- a/libraries/render-utils/src/Outline.slh +++ b/libraries/render-utils/src/Highlight.slh @@ -1,7 +1,7 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> <$declareDeferredFrameTransform()$> -<@include Outline_shared.slh@> +<@include Highlight_shared.slh@> -uniform outlineParamsBuffer { - OutlineParameters params; +uniform highlightParamsBuffer { + HighlightParameters params; }; uniform sampler2D sceneDepthMap; -uniform sampler2D outlinedDepthMap; +uniform sampler2D highlightedDepthMap; in vec2 varTexCoord0; out vec4 outFragColor; @@ -35,20 +35,20 @@ void main(void) { // We offset by half a texel to be centered on the depth sample. If we don't do this // the blur will have a different width between the left / right sides and top / bottom // sides of the silhouette - float outlinedDepth = texture(outlinedDepthMap, varTexCoord0).x; + float highlightedDepth = texture(highlightedDepthMap, varTexCoord0).x; float intensity = 0.0; - if (outlinedDepth < FAR_Z) { - // We're not on the far plane so we are on the outlined object, thus no outline to do! + if (highlightedDepth < FAR_Z) { + // We're not on the far plane so we are on the highlighted object, thus no outline to do! <@if IS_FILLED@> // But we need to fill the interior float sceneDepth = texture(sceneDepthMap, varTexCoord0).x; // Transform to linear depth for better precision - outlinedDepth = -evalZeyeFromZdb(outlinedDepth); + highlightedDepth = -evalZeyeFromZdb(highlightedDepth); sceneDepth = -evalZeyeFromZdb(sceneDepth); // Are we occluded? - intensity = sceneDepth < (outlinedDepth-LINEAR_DEPTH_BIAS) ? params._occludedFillOpacity : params._unoccludedFillOpacity; + intensity = sceneDepth < (highlightedDepth-LINEAR_DEPTH_BIAS) ? params._occludedFillOpacity : params._unoccludedFillOpacity; <@else@> discard; <@endif@> @@ -70,8 +70,8 @@ void main(void) { for (x=0 ; x=0.0 && uv.x<=1.0) { - outlinedDepth = texture(outlinedDepthMap, uv).x; - intensity += (outlinedDepth < FAR_Z) ? 1.0 : 0.0; + highlightedDepth = texture(highlightedDepthMap, uv).x; + intensity += (highlightedDepth < FAR_Z) ? 1.0 : 0.0; weight += 1.0; } uv.x += deltaUv.x; diff --git a/libraries/render-utils/src/OutlineEffect.cpp b/libraries/render-utils/src/HighlightEffect.cpp similarity index 63% rename from libraries/render-utils/src/OutlineEffect.cpp rename to libraries/render-utils/src/HighlightEffect.cpp index 590277bf6d..e332be53de 100644 --- a/libraries/render-utils/src/OutlineEffect.cpp +++ b/libraries/render-utils/src/HighlightEffect.cpp @@ -1,5 +1,5 @@ // -// OutlineEffect.cpp +// HighlightEffect.cpp // render-utils/src/ // // Created by Olivier Prat on 08/08/17. @@ -8,7 +8,7 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "OutlineEffect.h" +#include "HighlightEffect.h" #include "GeometryCache.h" @@ -25,18 +25,19 @@ #include "surfaceGeometry_copyDepth_frag.h" #include "debug_deferred_buffer_vert.h" #include "debug_deferred_buffer_frag.h" -#include "Outline_frag.h" -#include "Outline_filled_frag.h" -#include "Outline_aabox_vert.h" +#include "Highlight_frag.h" +#include "Highlight_filled_frag.h" +#include "Highlight_aabox_vert.h" +#include "nop_frag.h" using namespace render; #define OUTLINE_STENCIL_MASK 1 -OutlineRessources::OutlineRessources() { +HighlightRessources::HighlightRessources() { } -void OutlineRessources::update(const gpu::FramebufferPointer& primaryFrameBuffer) { +void HighlightRessources::update(const gpu::FramebufferPointer& primaryFrameBuffer) { auto newFrameSize = glm::ivec2(primaryFrameBuffer->getSize()); // If the buffer size changed, we need to delete our FBOs and recreate them at the @@ -55,64 +56,64 @@ void OutlineRessources::update(const gpu::FramebufferPointer& primaryFrameBuffer } } -void OutlineRessources::allocateColorBuffer(const gpu::FramebufferPointer& primaryFrameBuffer) { +void HighlightRessources::allocateColorBuffer(const gpu::FramebufferPointer& primaryFrameBuffer) { _colorFrameBuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("primaryWithStencil")); _colorFrameBuffer->setRenderBuffer(0, primaryFrameBuffer->getRenderBuffer(0)); _colorFrameBuffer->setDepthStencilBuffer(_depthStencilTexture, _depthStencilTexture->getTexelFormat()); } -void OutlineRessources::allocateDepthBuffer(const gpu::FramebufferPointer& primaryFrameBuffer) { +void HighlightRessources::allocateDepthBuffer(const gpu::FramebufferPointer& primaryFrameBuffer) { auto depthFormat = gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::DEPTH_STENCIL); _depthStencilTexture = gpu::TexturePointer(gpu::Texture::createRenderBuffer(depthFormat, _frameSize.x, _frameSize.y)); - _depthFrameBuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("outlineDepth")); + _depthFrameBuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("highlightDepth")); _depthFrameBuffer->setDepthStencilBuffer(_depthStencilTexture, depthFormat); } -gpu::FramebufferPointer OutlineRessources::getDepthFramebuffer() { +gpu::FramebufferPointer HighlightRessources::getDepthFramebuffer() { assert(_depthFrameBuffer); return _depthFrameBuffer; } -gpu::TexturePointer OutlineRessources::getDepthTexture() { +gpu::TexturePointer HighlightRessources::getDepthTexture() { return _depthStencilTexture; } -gpu::FramebufferPointer OutlineRessources::getColorFramebuffer() { +gpu::FramebufferPointer HighlightRessources::getColorFramebuffer() { assert(_colorFrameBuffer); return _colorFrameBuffer; } -OutlineSharedParameters::OutlineSharedParameters() { - _outlineIds.fill(render::OutlineStyleStage::INVALID_INDEX); +HighlightSharedParameters::HighlightSharedParameters() { + _highlightIds.fill(render::HighlightStage::INVALID_INDEX); } -float OutlineSharedParameters::getBlurPixelWidth(const render::OutlineStyle& style, int frameBufferHeight) { - return ceilf(style.width * frameBufferHeight / 400.0f); +float HighlightSharedParameters::getBlurPixelWidth(const render::HighlightStyle& style, int frameBufferHeight) { + return ceilf(style.outlineWidth * frameBufferHeight / 400.0f); } -PrepareDrawOutline::PrepareDrawOutline() { - _ressources = std::make_shared(); +PrepareDrawHighlight::PrepareDrawHighlight() { + _ressources = std::make_shared(); } -void PrepareDrawOutline::run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs) { +void PrepareDrawHighlight::run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs) { auto destinationFrameBuffer = inputs; _ressources->update(destinationFrameBuffer); outputs = _ressources; } -gpu::PipelinePointer DrawOutlineMask::_stencilMaskPipeline; -gpu::PipelinePointer DrawOutlineMask::_stencilMaskFillPipeline; -gpu::BufferPointer DrawOutlineMask::_boundsBuffer; +gpu::PipelinePointer DrawHighlightMask::_stencilMaskPipeline; +gpu::PipelinePointer DrawHighlightMask::_stencilMaskFillPipeline; +gpu::BufferPointer DrawHighlightMask::_boundsBuffer; -DrawOutlineMask::DrawOutlineMask(unsigned int outlineIndex, - render::ShapePlumberPointer shapePlumber, OutlineSharedParametersPointer parameters) : - _outlineIndex{ outlineIndex }, +DrawHighlightMask::DrawHighlightMask(unsigned int highlightIndex, + render::ShapePlumberPointer shapePlumber, HighlightSharedParametersPointer parameters) : + _highlightIndex{ highlightIndex }, _shapePlumber { shapePlumber }, _sharedParameters{ parameters } { } -void DrawOutlineMask::run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs) { +void DrawHighlightMask::run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs) { assert(renderContext->args); assert(renderContext->args->hasViewFrustum()); auto& inShapes = inputs.get0(); @@ -130,8 +131,8 @@ void DrawOutlineMask::run(const render::RenderContextPointer& renderContext, con fillState->setColorWriteMask(false, false, false, false); fillState->setCullMode(gpu::State::CULL_FRONT); - auto vs = gpu::Shader::createVertex(std::string(Outline_aabox_vert)); - auto ps = gpu::StandardShaderLib::getDrawWhitePS(); + auto vs = gpu::Shader::createVertex(std::string(Highlight_aabox_vert)); + auto ps = gpu::Shader::createPixel(std::string(nop_frag)); gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps); gpu::Shader::BindingSet slotBindings; @@ -145,12 +146,12 @@ void DrawOutlineMask::run(const render::RenderContextPointer& renderContext, con _boundsBuffer = std::make_shared(sizeof(render::ItemBound)); } - auto outlineStage = renderContext->_scene->getStage(render::OutlineStyleStage::getName()); - auto outlineId = _sharedParameters->_outlineIds[_outlineIndex]; + auto highlightStage = renderContext->_scene->getStage(render::HighlightStage::getName()); + auto highlightId = _sharedParameters->_highlightIds[_highlightIndex]; - if (!inShapes.empty() && !render::OutlineStyleStage::isIndexInvalid(outlineId)) { + if (!inShapes.empty() && !render::HighlightStage::isIndexInvalid(highlightId)) { auto ressources = inputs.get1(); - auto& outline = outlineStage->getOutline(outlineId); + auto& highlight = highlightStage->getHighlight(highlightId); RenderArgs* args = renderContext->args; ShapeKey::Builder defaultKeyBuilder; @@ -219,62 +220,62 @@ void DrawOutlineMask::run(const render::RenderContextPointer& renderContext, con batch.setViewTransform(viewMat); // Draw stencil mask with object bounding boxes - const auto outlineWidthLoc = _stencilMaskPipeline->getProgram()->getUniforms().findLocation("outlineWidth"); + const auto highlightWidthLoc = _stencilMaskPipeline->getProgram()->getUniforms().findLocation("outlineWidth"); const auto sqrt3 = 1.74f; - const float blurPixelWidth = 2.0f * sqrt3 * OutlineSharedParameters::getBlurPixelWidth(outline._style, args->_viewport.w); + const float blurPixelWidth = 2.0f * sqrt3 * HighlightSharedParameters::getBlurPixelWidth(highlight._style, args->_viewport.w); const auto framebufferSize = ressources->getSourceFrameSize(); - auto stencilPipeline = outline._style.isFilled() ? _stencilMaskFillPipeline : _stencilMaskPipeline; + auto stencilPipeline = highlight._style.isFilled() ? _stencilMaskFillPipeline : _stencilMaskPipeline; batch.setPipeline(stencilPipeline); batch.setResourceBuffer(0, _boundsBuffer); - batch._glUniform2f(outlineWidthLoc, blurPixelWidth / framebufferSize.x, blurPixelWidth / framebufferSize.y); + batch._glUniform2f(highlightWidthLoc, blurPixelWidth / framebufferSize.x, blurPixelWidth / framebufferSize.y); static const int NUM_VERTICES_PER_CUBE = 36; batch.draw(gpu::TRIANGLES, NUM_VERTICES_PER_CUBE * (gpu::uint32) itemBounds.size(), 0); }); } else { - // Outline rect should be null as there are no outlined shapes + // Highlight rect should be null as there are no highlighted shapes outputs = glm::ivec4(0, 0, 0, 0); } } -gpu::PipelinePointer DrawOutline::_pipeline; -gpu::PipelinePointer DrawOutline::_pipelineFilled; +gpu::PipelinePointer DrawHighlight::_pipeline; +gpu::PipelinePointer DrawHighlight::_pipelineFilled; -DrawOutline::DrawOutline(unsigned int outlineIndex, OutlineSharedParametersPointer parameters) : - _outlineIndex{ outlineIndex }, +DrawHighlight::DrawHighlight(unsigned int highlightIndex, HighlightSharedParametersPointer parameters) : + _highlightIndex{ highlightIndex }, _sharedParameters{ parameters } { } -void DrawOutline::run(const render::RenderContextPointer& renderContext, const Inputs& inputs) { - auto outlineFrameBuffer = inputs.get1(); - auto outlineRect = inputs.get3(); +void DrawHighlight::run(const render::RenderContextPointer& renderContext, const Inputs& inputs) { + auto highlightFrameBuffer = inputs.get1(); + auto highlightRect = inputs.get3(); - if (outlineFrameBuffer && outlineRect.z>0 && outlineRect.w>0) { + if (highlightFrameBuffer && highlightRect.z>0 && highlightRect.w>0) { auto sceneDepthBuffer = inputs.get2(); const auto frameTransform = inputs.get0(); - auto outlinedDepthTexture = outlineFrameBuffer->getDepthTexture(); - auto destinationFrameBuffer = outlineFrameBuffer->getColorFramebuffer(); - auto framebufferSize = glm::ivec2(outlinedDepthTexture->getDimensions()); + auto highlightedDepthTexture = highlightFrameBuffer->getDepthTexture(); + auto destinationFrameBuffer = highlightFrameBuffer->getColorFramebuffer(); + auto framebufferSize = glm::ivec2(highlightedDepthTexture->getDimensions()); if (sceneDepthBuffer) { auto args = renderContext->args; - auto outlineStage = renderContext->_scene->getStage(render::OutlineStyleStage::getName()); - auto outlineId = _sharedParameters->_outlineIds[_outlineIndex]; - if (!render::OutlineStyleStage::isIndexInvalid(outlineId)) { - auto& outline = outlineStage->getOutline(_sharedParameters->_outlineIds[_outlineIndex]); - auto pipeline = getPipeline(outline._style); + auto highlightStage = renderContext->_scene->getStage(render::HighlightStage::getName()); + auto highlightId = _sharedParameters->_highlightIds[_highlightIndex]; + if (!render::HighlightStage::isIndexInvalid(highlightId)) { + auto& highlight = highlightStage->getHighlight(_sharedParameters->_highlightIds[_highlightIndex]); + auto pipeline = getPipeline(highlight._style); { auto& shaderParameters = _configuration.edit(); - shaderParameters._color = outline._style.color; - shaderParameters._intensity = outline._style.intensity * (outline._style.glow ? 2.0f : 1.0f); - shaderParameters._unoccludedFillOpacity = outline._style.unoccludedFillOpacity; - shaderParameters._occludedFillOpacity = outline._style.occludedFillOpacity; - shaderParameters._threshold = outline._style.glow ? 1.0f : 1e-3f; - shaderParameters._blurKernelSize = std::min(7, std::max(2, (int)floorf(outline._style.width * 3 + 0.5f))); - // Size is in normalized screen height. We decide that for outline width = 1, this is equal to 1/400. - auto size = outline._style.width / 400.0f; + shaderParameters._color = highlight._style.color; + shaderParameters._intensity = highlight._style.outlineIntensity * (highlight._style.isOutlineSmooth ? 2.0f : 1.0f); + shaderParameters._unoccludedFillOpacity = highlight._style.unoccludedFillOpacity; + shaderParameters._occludedFillOpacity = highlight._style.occludedFillOpacity; + shaderParameters._threshold = highlight._style.isOutlineSmooth ? 1.0f : 1e-3f; + shaderParameters._blurKernelSize = std::min(7, std::max(2, (int)floorf(highlight._style.outlineWidth * 3 + 0.5f))); + // Size is in normalized screen height. We decide that for highlight width = 1, this is equal to 1/400. + auto size = highlight._style.outlineWidth / 400.0f; shaderParameters._size.x = (size * framebufferSize.y) / framebufferSize.x; shaderParameters._size.y = size; } @@ -289,10 +290,10 @@ void DrawOutline::run(const render::RenderContextPointer& renderContext, const I batch.setModelTransform(gpu::Framebuffer::evalSubregionTexcoordTransform(framebufferSize, args->_viewport)); batch.setPipeline(pipeline); - batch.setUniformBuffer(OUTLINE_PARAMS_SLOT, _configuration); + batch.setUniformBuffer(HIGHLIGHT_PARAMS_SLOT, _configuration); batch.setUniformBuffer(FRAME_TRANSFORM_SLOT, frameTransform->getFrameTransformBuffer()); - batch.setResourceTexture(SCENE_DEPTH_SLOT, sceneDepthBuffer->getPrimaryDepthTexture()); - batch.setResourceTexture(OUTLINED_DEPTH_SLOT, outlinedDepthTexture); + batch.setResourceTexture(SCENE_DEPTH_MAP_SLOT, sceneDepthBuffer->getPrimaryDepthTexture()); + batch.setResourceTexture(HIGHLIGHTED_DEPTH_MAP_SLOT, highlightedDepthTexture); batch.draw(gpu::TRIANGLE_STRIP, 4); }); } @@ -300,7 +301,7 @@ void DrawOutline::run(const render::RenderContextPointer& renderContext, const I } } -const gpu::PipelinePointer& DrawOutline::getPipeline(const render::OutlineStyle& style) { +const gpu::PipelinePointer& DrawHighlight::getPipeline(const render::HighlightStyle& style) { if (!_pipeline) { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); state->setDepthTest(gpu::State::DepthTest(false, false)); @@ -308,19 +309,19 @@ const gpu::PipelinePointer& DrawOutline::getPipeline(const render::OutlineStyle& state->setStencilTest(true, 0, gpu::State::StencilTest(OUTLINE_STENCIL_MASK, 0xFF, gpu::EQUAL)); auto vs = gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS(); - auto ps = gpu::Shader::createPixel(std::string(Outline_frag)); + auto ps = gpu::Shader::createPixel(std::string(Highlight_frag)); gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps); gpu::Shader::BindingSet slotBindings; - slotBindings.insert(gpu::Shader::Binding("outlineParamsBuffer", OUTLINE_PARAMS_SLOT)); + slotBindings.insert(gpu::Shader::Binding("highlightParamsBuffer", HIGHLIGHT_PARAMS_SLOT)); slotBindings.insert(gpu::Shader::Binding("deferredFrameTransformBuffer", FRAME_TRANSFORM_SLOT)); - slotBindings.insert(gpu::Shader::Binding("sceneDepthMap", SCENE_DEPTH_SLOT)); - slotBindings.insert(gpu::Shader::Binding("outlinedDepthMap", OUTLINED_DEPTH_SLOT)); + slotBindings.insert(gpu::Shader::Binding("sceneDepthMap", SCENE_DEPTH_MAP_SLOT)); + slotBindings.insert(gpu::Shader::Binding("highlightedDepthMap", HIGHLIGHTED_DEPTH_MAP_SLOT)); gpu::Shader::makeProgram(*program, slotBindings); _pipeline = gpu::Pipeline::create(program, state); - ps = gpu::Shader::createPixel(std::string(Outline_filled_frag)); + ps = gpu::Shader::createPixel(std::string(Highlight_filled_frag)); program = gpu::Shader::createProgram(vs, ps); gpu::Shader::makeProgram(*program, slotBindings); _pipelineFilled = gpu::Pipeline::create(program, state); @@ -328,33 +329,33 @@ const gpu::PipelinePointer& DrawOutline::getPipeline(const render::OutlineStyle& return style.isFilled() ? _pipelineFilled : _pipeline; } -DebugOutline::DebugOutline() { +DebugHighlight::DebugHighlight() { _geometryDepthId = DependencyManager::get()->allocateID(); } -DebugOutline::~DebugOutline() { +DebugHighlight::~DebugHighlight() { auto geometryCache = DependencyManager::get(); if (geometryCache) { geometryCache->releaseID(_geometryDepthId); } } -void DebugOutline::configure(const Config& config) { +void DebugHighlight::configure(const Config& config) { _isDisplayEnabled = config.viewMask; } -void DebugOutline::run(const render::RenderContextPointer& renderContext, const Inputs& input) { - const auto outlineRessources = input.get0(); - const auto outlineRect = input.get1(); +void DebugHighlight::run(const render::RenderContextPointer& renderContext, const Inputs& input) { + const auto highlightRessources = input.get0(); + const auto highlightRect = input.get1(); - if (_isDisplayEnabled && outlineRessources && outlineRect.z>0 && outlineRect.w>0) { + if (_isDisplayEnabled && highlightRessources && highlightRect.z>0 && highlightRect.w>0) { assert(renderContext->args); assert(renderContext->args->hasViewFrustum()); RenderArgs* args = renderContext->args; gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { batch.setViewportTransform(args->_viewport); - batch.setFramebuffer(outlineRessources->getColorFramebuffer()); + batch.setFramebuffer(highlightRessources->getColorFramebuffer()); const auto geometryBuffer = DependencyManager::get(); @@ -369,7 +370,7 @@ void DebugOutline::run(const render::RenderContextPointer& renderContext, const const glm::vec4 color(1.0f, 1.0f, 1.0f, 1.0f); batch.setPipeline(getDepthPipeline()); - batch.setResourceTexture(0, outlineRessources->getDepthTexture()); + batch.setResourceTexture(0, highlightRessources->getDepthTexture()); const glm::vec2 bottomLeft(-1.0f, -1.0f); const glm::vec2 topRight(1.0f, 1.0f); geometryBuffer->renderQuad(batch, bottomLeft, topRight, color, _geometryDepthId); @@ -379,7 +380,7 @@ void DebugOutline::run(const render::RenderContextPointer& renderContext, const } } -void DebugOutline::initializePipelines() { +void DebugHighlight::initializePipelines() { static const std::string VERTEX_SHADER{ debug_deferred_buffer_vert }; static const std::string FRAGMENT_SHADER{ debug_deferred_buffer_frag }; static const std::string SOURCE_PLACEHOLDER{ "//SOURCE_PLACEHOLDER" }; @@ -417,7 +418,7 @@ void DebugOutline::initializePipelines() { } } -const gpu::PipelinePointer& DebugOutline::getDepthPipeline() { +const gpu::PipelinePointer& DebugHighlight::getDepthPipeline() { if (!_depthPipeline) { initializePipelines(); } @@ -425,44 +426,44 @@ const gpu::PipelinePointer& DebugOutline::getDepthPipeline() { return _depthPipeline; } -void SelectionToOutline::run(const render::RenderContextPointer& renderContext, Outputs& outputs) { - auto outlineStage = renderContext->_scene->getStage(render::OutlineStyleStage::getName()); +void SelectionToHighlight::run(const render::RenderContextPointer& renderContext, Outputs& outputs) { + auto highlightStage = renderContext->_scene->getStage(render::HighlightStage::getName()); outputs.clear(); - _sharedParameters->_outlineIds.fill(render::OutlineStyleStage::INVALID_INDEX); + _sharedParameters->_highlightIds.fill(render::HighlightStage::INVALID_INDEX); - for (auto i = 0; i < OutlineSharedParameters::MAX_OUTLINE_COUNT; i++) { + for (auto i = 0; i < HighlightSharedParameters::MAX_HIGHLIGHT_COUNT; i++) { std::ostringstream stream; stream << "contextOverlayHighlightList"; if (i > 0) { stream << i; } auto selectionName = stream.str(); - auto outlineId = outlineStage->getOutlineIdBySelection(selectionName); - if (!render::OutlineStyleStage::isIndexInvalid(outlineId)) { - _sharedParameters->_outlineIds[outputs.size()] = outlineId; + auto highlightId = highlightStage->getHighlightIdBySelection(selectionName); + if (!render::HighlightStage::isIndexInvalid(highlightId)) { + _sharedParameters->_highlightIds[outputs.size()] = highlightId; outputs.emplace_back(selectionName); } } } void ExtractSelectionName::run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs) { - if (_outlineIndex < inputs.size()) { - outputs = inputs[_outlineIndex]; + if (_highlightIndex < inputs.size()) { + outputs = inputs[_highlightIndex]; } else { outputs.clear(); } } -DrawOutlineTask::DrawOutlineTask() { +DrawHighlightTask::DrawHighlightTask() { } -void DrawOutlineTask::configure(const Config& config) { +void DrawHighlightTask::configure(const Config& config) { } -void DrawOutlineTask::build(JobModel& task, const render::Varying& inputs, render::Varying& outputs) { +void DrawHighlightTask::build(JobModel& task, const render::Varying& inputs, render::Varying& outputs) { const auto items = inputs.getN(0).get(); const auto sceneFrameBuffer = inputs.getN(1); const auto primaryFramebuffer = inputs.getN(2); @@ -477,53 +478,53 @@ void DrawOutlineTask::build(JobModel& task, const render::Varying& inputs, rende initMaskPipelines(*shapePlumber, state); } - auto sharedParameters = std::make_shared(); + auto sharedParameters = std::make_shared(); - const auto outlineSelectionNames = task.addJob("SelectionToOutline", sharedParameters); + const auto highlightSelectionNames = task.addJob("SelectionToHighlight", sharedParameters); - // Prepare for outline group rendering. - const auto outlineRessources = task.addJob("PrepareOutline", primaryFramebuffer); - render::Varying outline0Rect; + // Prepare for highlight group rendering. + const auto highlightRessources = task.addJob("PrepareHighlight", primaryFramebuffer); + render::Varying highlight0Rect; - for (auto i = 0; i < OutlineSharedParameters::MAX_OUTLINE_COUNT; i++) { - const auto selectionName = task.addJob("ExtractSelectionName", outlineSelectionNames, i); + for (auto i = 0; i < HighlightSharedParameters::MAX_HIGHLIGHT_COUNT; i++) { + const auto selectionName = task.addJob("ExtractSelectionName", highlightSelectionNames, i); const auto groupItems = addSelectItemJobs(task, selectionName, items); - const auto outlinedItemIDs = task.addJob("OutlineMetaToSubItemIDs", groupItems); - const auto outlinedItems = task.addJob("OutlineMetaToSubItems", outlinedItemIDs); + const auto highlightedItemIDs = task.addJob("HighlightMetaToSubItemIDs", groupItems); + const auto highlightedItems = task.addJob("HighlightMetaToSubItems", highlightedItemIDs); // Sort - const auto sortedPipelines = task.addJob("OutlinePipelineSort", outlinedItems); - const auto sortedBounds = task.addJob("OutlineDepthSort", sortedPipelines); + const auto sortedPipelines = task.addJob("HighlightPipelineSort", highlightedItems); + const auto sortedBounds = task.addJob("HighlightDepthSort", sortedPipelines); - // Draw depth of outlined objects in separate buffer + // Draw depth of highlighted objects in separate buffer std::string name; { std::ostringstream stream; - stream << "OutlineMask" << i; + stream << "HighlightMask" << i; name = stream.str(); } - const auto drawMaskInputs = DrawOutlineMask::Inputs(sortedBounds, outlineRessources).asVarying(); - const auto outlinedRect = task.addJob(name, drawMaskInputs, i, shapePlumber, sharedParameters); + const auto drawMaskInputs = DrawHighlightMask::Inputs(sortedBounds, highlightRessources).asVarying(); + const auto highlightedRect = task.addJob(name, drawMaskInputs, i, shapePlumber, sharedParameters); if (i == 0) { - outline0Rect = outlinedRect; + highlight0Rect = highlightedRect; } - // Draw outline + // Draw highlight { std::ostringstream stream; - stream << "OutlineEffect" << i; + stream << "HighlightEffect" << i; name = stream.str(); } - const auto drawOutlineInputs = DrawOutline::Inputs(deferredFrameTransform, outlineRessources, sceneFrameBuffer, outlinedRect).asVarying(); - task.addJob(name, drawOutlineInputs, i, sharedParameters); + const auto drawHighlightInputs = DrawHighlight::Inputs(deferredFrameTransform, highlightRessources, sceneFrameBuffer, highlightedRect).asVarying(); + task.addJob(name, drawHighlightInputs, i, sharedParameters); } - // Debug outline - const auto debugInputs = DebugOutline::Inputs(outlineRessources, const_cast(outline0Rect)).asVarying(); - task.addJob("OutlineDebug", debugInputs); + // Debug highlight + const auto debugInputs = DebugHighlight::Inputs(highlightRessources, const_cast(highlight0Rect)).asVarying(); + task.addJob("HighlightDebug", debugInputs); } -const render::Varying DrawOutlineTask::addSelectItemJobs(JobModel& task, const render::Varying& selectionName, +const render::Varying DrawHighlightTask::addSelectItemJobs(JobModel& task, const render::Varying& selectionName, const RenderFetchCullSortTask::BucketList& items) { const auto& opaques = items[RenderFetchCullSortTask::OPAQUE_SHAPE]; const auto& transparents = items[RenderFetchCullSortTask::TRANSPARENT_SHAPE]; @@ -542,7 +543,7 @@ const render::Varying DrawOutlineTask::addSelectItemJobs(JobModel& task, const r #include "model_shadow_frag.h" -void DrawOutlineTask::initMaskPipelines(render::ShapePlumber& shapePlumber, gpu::StatePointer state) { +void DrawHighlightTask::initMaskPipelines(render::ShapePlumber& shapePlumber, gpu::StatePointer state) { auto modelVertex = gpu::Shader::createVertex(std::string(model_shadow_vert)); auto modelPixel = gpu::Shader::createPixel(std::string(model_shadow_frag)); gpu::ShaderPointer modelProgram = gpu::Shader::createProgram(modelVertex, modelPixel); diff --git a/libraries/render-utils/src/OutlineEffect.h b/libraries/render-utils/src/HighlightEffect.h similarity index 55% rename from libraries/render-utils/src/OutlineEffect.h rename to libraries/render-utils/src/HighlightEffect.h index e25184eb5b..0531c03efd 100644 --- a/libraries/render-utils/src/OutlineEffect.h +++ b/libraries/render-utils/src/HighlightEffect.h @@ -1,5 +1,5 @@ // -// OutlineEffect.h +// HighlightEffect.h // render-utils/src/ // // Created by Olivier Prat on 08/08/17. @@ -9,19 +9,19 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_render_utils_OutlineEffect_h -#define hifi_render_utils_OutlineEffect_h +#ifndef hifi_render_utils_HighlightEffect_h +#define hifi_render_utils_HighlightEffect_h #include -#include +#include #include #include "DeferredFramebuffer.h" #include "DeferredFrameTransform.h" -class OutlineRessources { +class HighlightRessources { public: - OutlineRessources(); + HighlightRessources(); gpu::FramebufferPointer getDepthFramebuffer(); gpu::TexturePointer getDepthTexture(); @@ -44,131 +44,131 @@ protected: void allocateDepthBuffer(const gpu::FramebufferPointer& primaryFrameBuffer); }; -using OutlineRessourcesPointer = std::shared_ptr; +using HighlightRessourcesPointer = std::shared_ptr; -class OutlineSharedParameters { +class HighlightSharedParameters { public: enum { - MAX_OUTLINE_COUNT = 8 + MAX_HIGHLIGHT_COUNT = 8 }; - OutlineSharedParameters(); + HighlightSharedParameters(); - std::array _outlineIds; + std::array _highlightIds; - static float getBlurPixelWidth(const render::OutlineStyle& style, int frameBufferHeight); + static float getBlurPixelWidth(const render::HighlightStyle& style, int frameBufferHeight); }; -using OutlineSharedParametersPointer = std::shared_ptr; +using HighlightSharedParametersPointer = std::shared_ptr; -class PrepareDrawOutline { +class PrepareDrawHighlight { public: using Inputs = gpu::FramebufferPointer; - using Outputs = OutlineRessourcesPointer; - using JobModel = render::Job::ModelIO; + using Outputs = HighlightRessourcesPointer; + using JobModel = render::Job::ModelIO; - PrepareDrawOutline(); + PrepareDrawHighlight(); void run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs); private: - OutlineRessourcesPointer _ressources; + HighlightRessourcesPointer _ressources; }; -class SelectionToOutline { +class SelectionToHighlight { public: using Outputs = std::vector; - using JobModel = render::Job::ModelO; + using JobModel = render::Job::ModelO; - SelectionToOutline(OutlineSharedParametersPointer parameters) : _sharedParameters{ parameters } {} + SelectionToHighlight(HighlightSharedParametersPointer parameters) : _sharedParameters{ parameters } {} void run(const render::RenderContextPointer& renderContext, Outputs& outputs); private: - OutlineSharedParametersPointer _sharedParameters; + HighlightSharedParametersPointer _sharedParameters; }; class ExtractSelectionName { public: - using Inputs = SelectionToOutline::Outputs; + using Inputs = SelectionToHighlight::Outputs; using Outputs = std::string; using JobModel = render::Job::ModelIO; - ExtractSelectionName(unsigned int outlineIndex) : _outlineIndex{ outlineIndex } {} + ExtractSelectionName(unsigned int highlightIndex) : _highlightIndex{ highlightIndex } {} void run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs); private: - unsigned int _outlineIndex; + unsigned int _highlightIndex; }; -class DrawOutlineMask { +class DrawHighlightMask { public: - using Inputs = render::VaryingSet2; + using Inputs = render::VaryingSet2; using Outputs = glm::ivec4; - using JobModel = render::Job::ModelIO; + using JobModel = render::Job::ModelIO; - DrawOutlineMask(unsigned int outlineIndex, render::ShapePlumberPointer shapePlumber, OutlineSharedParametersPointer parameters); + DrawHighlightMask(unsigned int highlightIndex, render::ShapePlumberPointer shapePlumber, HighlightSharedParametersPointer parameters); void run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs); protected: - unsigned int _outlineIndex; + unsigned int _highlightIndex; render::ShapePlumberPointer _shapePlumber; - OutlineSharedParametersPointer _sharedParameters; + HighlightSharedParametersPointer _sharedParameters; static gpu::BufferPointer _boundsBuffer; static gpu::PipelinePointer _stencilMaskPipeline; static gpu::PipelinePointer _stencilMaskFillPipeline; }; -class DrawOutline { +class DrawHighlight { public: - using Inputs = render::VaryingSet4; + using Inputs = render::VaryingSet4; using Config = render::Job::Config; - using JobModel = render::Job::ModelI; + using JobModel = render::Job::ModelI; - DrawOutline(unsigned int outlineIndex, OutlineSharedParametersPointer parameters); + DrawHighlight(unsigned int highlightIndex, HighlightSharedParametersPointer parameters); void run(const render::RenderContextPointer& renderContext, const Inputs& inputs); private: -#include "Outline_shared.slh" +#include "Highlight_shared.slh" enum { - SCENE_DEPTH_SLOT = 0, - OUTLINED_DEPTH_SLOT, + SCENE_DEPTH_MAP_SLOT = 0, + HIGHLIGHTED_DEPTH_MAP_SLOT, - OUTLINE_PARAMS_SLOT = 0, + HIGHLIGHT_PARAMS_SLOT = 0, FRAME_TRANSFORM_SLOT, }; - using OutlineConfigurationBuffer = gpu::StructBuffer; + using HighlightConfigurationBuffer = gpu::StructBuffer; - static const gpu::PipelinePointer& getPipeline(const render::OutlineStyle& style); + static const gpu::PipelinePointer& getPipeline(const render::HighlightStyle& style); static gpu::PipelinePointer _pipeline; static gpu::PipelinePointer _pipelineFilled; - unsigned int _outlineIndex; - OutlineParameters _parameters; - OutlineSharedParametersPointer _sharedParameters; - OutlineConfigurationBuffer _configuration; + unsigned int _highlightIndex; + HighlightParameters _parameters; + HighlightSharedParametersPointer _sharedParameters; + HighlightConfigurationBuffer _configuration; }; -class DebugOutlineConfig : public render::Job::Config { +class DebugHighlightConfig : public render::Job::Config { Q_OBJECT Q_PROPERTY(bool viewMask MEMBER viewMask NOTIFY dirty) @@ -180,14 +180,14 @@ signals: void dirty(); }; -class DebugOutline { +class DebugHighlight { public: - using Inputs = render::VaryingSet2; - using Config = DebugOutlineConfig; - using JobModel = render::Job::ModelI; + using Inputs = render::VaryingSet2; + using Config = DebugHighlightConfig; + using JobModel = render::Job::ModelI; - DebugOutline(); - ~DebugOutline(); + DebugHighlight(); + ~DebugHighlight(); void configure(const Config& config); void run(const render::RenderContextPointer& renderContext, const Inputs& inputs); @@ -202,14 +202,14 @@ private: void initializePipelines(); }; -class DrawOutlineTask { +class DrawHighlightTask { public: using Inputs = render::VaryingSet4; using Config = render::Task::Config; - using JobModel = render::Task::ModelI; + using JobModel = render::Task::ModelI; - DrawOutlineTask(); + DrawHighlightTask(); void configure(const Config& config); void build(JobModel& task, const render::Varying& inputs, render::Varying& outputs); @@ -221,6 +221,6 @@ private: }; -#endif // hifi_render_utils_OutlineEffect_h +#endif // hifi_render_utils_HighlightEffect_h diff --git a/libraries/render-utils/src/Outline_aabox.slv b/libraries/render-utils/src/Highlight_aabox.slv similarity index 100% rename from libraries/render-utils/src/Outline_aabox.slv rename to libraries/render-utils/src/Highlight_aabox.slv diff --git a/libraries/render-utils/src/Outline_filled.slf b/libraries/render-utils/src/Highlight_filled.slf similarity index 71% rename from libraries/render-utils/src/Outline_filled.slf rename to libraries/render-utils/src/Highlight_filled.slf index aaa3396bac..53530746f0 100644 --- a/libraries/render-utils/src/Outline_filled.slf +++ b/libraries/render-utils/src/Highlight_filled.slf @@ -1,5 +1,5 @@ -// Outline_filled.slf -// Add outline effect based on two zbuffers : one containing the total scene z and another +// Highlight_filled.slf +// Add highlight effect based on two zbuffers : one containing the total scene z and another // with the z of only the objects to be outlined. // This is the version with the fill effect inside the silhouette. // @@ -9,5 +9,5 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -<@include Outline.slh@> +<@include Highlight.slh@> <$main(1)$> diff --git a/libraries/render-utils/src/Outline_shared.slh b/libraries/render-utils/src/Highlight_shared.slh similarity index 84% rename from libraries/render-utils/src/Outline_shared.slh rename to libraries/render-utils/src/Highlight_shared.slh index 3fd089e2fc..5efbde4d52 100644 --- a/libraries/render-utils/src/Outline_shared.slh +++ b/libraries/render-utils/src/Highlight_shared.slh @@ -1,4 +1,4 @@ -// glsl / C++ compatible source as interface for Outline +// glsl / C++ compatible source as interface for highlight #ifdef __cplusplus # define TVEC2 glm::vec2 # define TVEC3 glm::vec3 @@ -9,7 +9,7 @@ # define TVEC4 vec4 #endif -struct OutlineParameters +struct HighlightParameters { TVEC3 _color; float _intensity; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 52b8896e69..1f839b25eb 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -42,7 +42,7 @@ #include "ToneMappingEffect.h" #include "SubsurfaceScattering.h" #include "DrawHaze.h" -#include "OutlineEffect.h" +#include "HighlightEffect.h" #include @@ -183,15 +183,15 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto toneMappingInputs = ToneMappingDeferred::Inputs(lightingFramebuffer, primaryFramebuffer).asVarying(); task.addJob("ToneMapping", toneMappingInputs); - const auto outlineRangeTimer = task.addJob("BeginOutlineRangeTimer", "Outline"); + 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 = DrawOutlineTask::Inputs(items.get0(), deferredFramebuffer, primaryFramebuffer, deferredFrameTransform).asVarying(); - task.addJob("DrawOutline", outlineInputs); + const auto outlineInputs = DrawHighlightTask::Inputs(items.get0(), deferredFramebuffer, primaryFramebuffer, deferredFrameTransform).asVarying(); + task.addJob("DrawHighlight", outlineInputs); - task.addJob("OutlineRangeTimer", outlineRangeTimer); + task.addJob("HighlightRangeTimer", outlineRangeTimer); { // DEbug the bounds of the rendered items, still look at the zbuffer task.addJob("DrawMetaBounds", metas); diff --git a/libraries/render-utils/src/UpdateSceneTask.cpp b/libraries/render-utils/src/UpdateSceneTask.cpp index d37569b526..e05f28ef0d 100644 --- a/libraries/render-utils/src/UpdateSceneTask.cpp +++ b/libraries/render-utils/src/UpdateSceneTask.cpp @@ -15,7 +15,7 @@ #include "BackgroundStage.h" #include "HazeStage.h" #include -#include +#include #include "DeferredLightingEffect.h" void UpdateSceneTask::build(JobModel& task, const render::Varying& input, render::Varying& output) { @@ -23,7 +23,7 @@ void UpdateSceneTask::build(JobModel& task, const render::Varying& input, render task.addJob("BackgroundStageSetup"); task.addJob("HazeStageSetup"); task.addJob("TransitionStageSetup"); - task.addJob("OutlineStyleStageSetup"); + task.addJob("HighlightStageSetup"); task.addJob("DefaultLightingSetup"); diff --git a/libraries/render/src/render/HighlightStage.cpp b/libraries/render/src/render/HighlightStage.cpp new file mode 100644 index 0000000000..effb7c7e98 --- /dev/null +++ b/libraries/render/src/render/HighlightStage.cpp @@ -0,0 +1,46 @@ +#include "HighlightStage.h" + +using namespace render; + +std::string HighlightStage::_name("Highlight"); + +HighlightStage::Index HighlightStage::addHighlight(const std::string& selectionName, const HighlightStyle& style) { + Highlight outline{ selectionName, style }; + Index id; + + id = _highlights.newElement(outline); + _activeHighlightIds.push_back(id); + + return id; +} + +void HighlightStage::removeHighlight(Index index) { + HighlightIdList::iterator idIterator = std::find(_activeHighlightIds.begin(), _activeHighlightIds.end(), index); + if (idIterator != _activeHighlightIds.end()) { + _activeHighlightIds.erase(idIterator); + } + if (!_highlights.isElementFreed(index)) { + _highlights.freeElement(index); + } +} + +Index HighlightStage::getHighlightIdBySelection(const std::string& selectionName) const { + for (auto outlineId : _activeHighlightIds) { + const auto& outline = _highlights.get(outlineId); + if (outline._selectionName == selectionName) { + return outlineId; + } + } + return INVALID_INDEX; +} + +HighlightStageSetup::HighlightStageSetup() { +} + +void HighlightStageSetup::run(const render::RenderContextPointer& renderContext) { + if (!renderContext->_scene->getStage(HighlightStage::getName())) { + auto stage = std::make_shared(); + renderContext->_scene->resetStage(HighlightStage::getName(), stage); + } +} + diff --git a/libraries/render/src/render/HighlightStage.h b/libraries/render/src/render/HighlightStage.h new file mode 100644 index 0000000000..a2c123580c --- /dev/null +++ b/libraries/render/src/render/HighlightStage.h @@ -0,0 +1,77 @@ +// +// HighlightStage.h + +// Created by Olivier Prat on 07/07/2017. +// Copyright 2017 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_render_utils_HighlightStage_h +#define hifi_render_utils_HighlightStage_h + +#include "Stage.h" +#include "Engine.h" +#include "IndexedContainer.h" +#include "HighlightStyle.h" + +namespace render { + + // Highlight stage to set up HighlightStyle-related effects + class HighlightStage : public Stage { + public: + + class Highlight { + public: + + Highlight(const std::string& selectionName, const HighlightStyle& style) : _selectionName{ selectionName }, _style{ style } { } + + std::string _selectionName; + HighlightStyle _style; + + }; + + static const std::string& getName() { return _name; } + + using Index = render::indexed_container::Index; + static const Index INVALID_INDEX{ render::indexed_container::INVALID_INDEX }; + using HighlightIdList = render::indexed_container::Indices; + + static bool isIndexInvalid(Index index) { return index == INVALID_INDEX; } + + bool checkHighlightId(Index index) const { return _highlights.checkIndex(index); } + + const Highlight& getHighlight(Index index) const { return _highlights.get(index); } + Highlight& editHighlight(Index index) { return _highlights.edit(index); } + + Index addHighlight(const std::string& selectionName, const HighlightStyle& style = HighlightStyle()); + Index getHighlightIdBySelection(const std::string& selectionName) const; + void removeHighlight(Index index); + + HighlightIdList::iterator begin() { return _activeHighlightIds.begin(); } + HighlightIdList::iterator end() { return _activeHighlightIds.end(); } + + private: + + using Highlights = render::indexed_container::IndexedVector; + + static std::string _name; + + Highlights _highlights; + HighlightIdList _activeHighlightIds; + }; + using HighlightStagePointer = std::shared_ptr; + + class HighlightStageSetup { + public: + using JobModel = render::Job::Model; + + HighlightStageSetup(); + void run(const RenderContextPointer& renderContext); + + protected: + }; + +} +#endif // hifi_render_utils_HighlightStage_h diff --git a/libraries/render/src/render/OutlineStyle.h b/libraries/render/src/render/HighlightStyle.h similarity index 68% rename from libraries/render/src/render/OutlineStyle.h rename to libraries/render/src/render/HighlightStyle.h index cdcdf79f3e..6e7373c78b 100644 --- a/libraries/render/src/render/OutlineStyle.h +++ b/libraries/render/src/render/HighlightStyle.h @@ -1,5 +1,5 @@ // -// OutlineStyle.h +// HighlightStyle.h // Created by Olivier Prat on 11/06/2017. // Copyright 2017 High Fidelity, Inc. @@ -8,8 +8,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_render_utils_OutlineStyle_h -#define hifi_render_utils_OutlineStyle_h +#ifndef hifi_render_utils_HighlightStyle_h +#define hifi_render_utils_HighlightStyle_h #include @@ -18,7 +18,7 @@ namespace render { // This holds the configuration for a particular outline style - class OutlineStyle { + class HighlightStyle { public: bool isFilled() const { @@ -26,14 +26,13 @@ namespace render { } glm::vec3 color{ 1.f, 0.7f, 0.2f }; - float width{ 2.0f }; - float intensity{ 0.9f }; + float outlineWidth{ 2.0f }; + float outlineIntensity{ 0.9f }; float unoccludedFillOpacity{ 0.0f }; float occludedFillOpacity{ 0.0f }; - bool glow{ false }; - std::string selectionName; + bool isOutlineSmooth{ false }; }; } -#endif // hifi_render_utils_OutlineStyle_h \ No newline at end of file +#endif // hifi_render_utils_HighlightStyle_h \ No newline at end of file diff --git a/libraries/render/src/render/OutlineStyleStage.cpp b/libraries/render/src/render/OutlineStyleStage.cpp deleted file mode 100644 index e3fd1672de..0000000000 --- a/libraries/render/src/render/OutlineStyleStage.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "OutlineStyleStage.h" - -using namespace render; - -std::string OutlineStyleStage::_name("OutlineStyle"); - -OutlineStyleStage::Index OutlineStyleStage::addOutline(const std::string& selectionName, const OutlineStyle& style) { - Outline outline{ selectionName, style }; - Index id; - - id = _outlines.newElement(outline); - _activeOutlineIds.push_back(id); - - return id; -} - -void OutlineStyleStage::removeOutline(Index index) { - OutlineIdList::iterator idIterator = std::find(_activeOutlineIds.begin(), _activeOutlineIds.end(), index); - if (idIterator != _activeOutlineIds.end()) { - _activeOutlineIds.erase(idIterator); - } - if (!_outlines.isElementFreed(index)) { - _outlines.freeElement(index); - } -} - -Index OutlineStyleStage::getOutlineIdBySelection(const std::string& selectionName) const { - for (auto outlineId : _activeOutlineIds) { - const auto& outline = _outlines.get(outlineId); - if (outline._selectionName == selectionName) { - return outlineId; - } - } - return INVALID_INDEX; -} - -OutlineStyleStageSetup::OutlineStyleStageSetup() { -} - -void OutlineStyleStageSetup::run(const render::RenderContextPointer& renderContext) { - if (!renderContext->_scene->getStage(OutlineStyleStage::getName())) { - auto stage = std::make_shared(); - renderContext->_scene->resetStage(OutlineStyleStage::getName(), stage); - } -} - diff --git a/libraries/render/src/render/OutlineStyleStage.h b/libraries/render/src/render/OutlineStyleStage.h deleted file mode 100644 index 79835a22a4..0000000000 --- a/libraries/render/src/render/OutlineStyleStage.h +++ /dev/null @@ -1,77 +0,0 @@ -// -// OutlineStyleStage.h - -// Created by Olivier Prat on 07/07/2017. -// Copyright 2017 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_render_utils_outlinestage_h -#define hifi_render_utils_outlinestage_h - -#include "Stage.h" -#include "Engine.h" -#include "IndexedContainer.h" -#include "OutlineStyle.h" - -namespace render { - - // OutlineStyle stage to set up OutlineStyle-related effects - class OutlineStyleStage : public Stage { - public: - - class Outline { - public: - - Outline(const std::string& selectionName, const OutlineStyle& style) : _selectionName{ selectionName }, _style{ style } { } - - std::string _selectionName; - OutlineStyle _style; - - }; - - static const std::string& getName() { return _name; } - - using Index = render::indexed_container::Index; - static const Index INVALID_INDEX{ render::indexed_container::INVALID_INDEX }; - using OutlineIdList = render::indexed_container::Indices; - - static bool isIndexInvalid(Index index) { return index == INVALID_INDEX; } - - bool checkOutlineId(Index index) const { return _outlines.checkIndex(index); } - - const Outline& getOutline(Index OutlineStyleId) const { return _outlines.get(OutlineStyleId); } - Outline& editOutline(Index OutlineStyleId) { return _outlines.edit(OutlineStyleId); } - - Index addOutline(const std::string& selectionName, const OutlineStyle& style = OutlineStyle()); - Index getOutlineIdBySelection(const std::string& selectionName) const; - void removeOutline(Index index); - - OutlineIdList::iterator begin() { return _activeOutlineIds.begin(); } - OutlineIdList::iterator end() { return _activeOutlineIds.end(); } - - private: - - using Outlines = render::indexed_container::IndexedVector; - - static std::string _name; - - Outlines _outlines; - OutlineIdList _activeOutlineIds; - }; - using OutlineStyleStagePointer = std::shared_ptr; - - class OutlineStyleStageSetup { - public: - using JobModel = render::Job::Model; - - OutlineStyleStageSetup(); - void run(const RenderContextPointer& renderContext); - - protected: - }; - -} -#endif // hifi_render_utils_outlinestage_h diff --git a/libraries/render/src/render/Scene.cpp b/libraries/render/src/render/Scene.cpp index 0e680dfdaf..9cdaa89cf6 100644 --- a/libraries/render/src/render/Scene.cpp +++ b/libraries/render/src/render/Scene.cpp @@ -14,7 +14,7 @@ #include #include "Logging.h" #include "TransitionStage.h" -#include "OutlineStyleStage.h" +#include "HighlightStage.h" using namespace render; @@ -55,16 +55,16 @@ void Transaction::resetSelection(const Selection& selection) { _resetSelections.emplace_back(selection); } -void Transaction::resetSelectionOutline(const std::string& selectionName, const OutlineStyle& style) { - _outlineResets.emplace_back(OutlineReset{ selectionName, style }); +void Transaction::resetSelectionHighlight(const std::string& selectionName, const HighlightStyle& style) { + _highlightResets.emplace_back(HighlightReset{ selectionName, style }); } -void Transaction::removeOutlineFromSelection(const std::string& selectionName) { - _outlineRemoves.emplace_back(selectionName); +void Transaction::removeHighlightFromSelection(const std::string& selectionName) { + _highlightRemoves.emplace_back(selectionName); } -void Transaction::querySelectionOutline(const std::string& selectionName, SelectionOutlineQueryFunc func) { - _outlineQueries.emplace_back(OutlineQuery{ selectionName, func }); +void Transaction::querySelectionHighlight(const std::string& selectionName, SelectionHighlightQueryFunc func) { + _highlightQueries.emplace_back(HighlightQuery{ selectionName, func }); } void Transaction::merge(const Transaction& transaction) { @@ -75,9 +75,9 @@ void Transaction::merge(const Transaction& transaction) { _addedTransitions.insert(_addedTransitions.end(), transaction._addedTransitions.begin(), transaction._addedTransitions.end()); _queriedTransitions.insert(_queriedTransitions.end(), transaction._queriedTransitions.begin(), transaction._queriedTransitions.end()); _reAppliedTransitions.insert(_reAppliedTransitions.end(), transaction._reAppliedTransitions.begin(), transaction._reAppliedTransitions.end()); - _outlineResets.insert(_outlineResets.end(), transaction._outlineResets.begin(), transaction._outlineResets.end()); - _outlineRemoves.insert(_outlineRemoves.end(), transaction._outlineRemoves.begin(), transaction._outlineRemoves.end()); - _outlineQueries.insert(_outlineQueries.end(), transaction._outlineQueries.begin(), transaction._outlineQueries.end()); + _highlightResets.insert(_highlightResets.end(), transaction._highlightResets.begin(), transaction._highlightResets.end()); + _highlightRemoves.insert(_highlightRemoves.end(), transaction._highlightRemoves.begin(), transaction._highlightRemoves.end()); + _highlightQueries.insert(_highlightQueries.end(), transaction._highlightQueries.begin(), transaction._highlightQueries.end()); } @@ -193,9 +193,9 @@ void Scene::processTransactionFrame(const Transaction& transaction) { resetSelections(transaction._resetSelections); } - resetOutlines(transaction._outlineResets); - removeOutlines(transaction._outlineRemoves); - queryOutlines(transaction._outlineQueries); + resetHighlights(transaction._highlightResets); + removeHighlights(transaction._highlightRemoves); + queryHighlights(transaction._highlightQueries); } void Scene::resetItems(const Transaction::Resets& transactions) { @@ -336,44 +336,44 @@ void Scene::queryTransitionItems(const Transaction::TransitionQueries& transacti } } -void Scene::resetOutlines(const Transaction::OutlineResets& transactions) { - auto outlineStage = getStage(OutlineStyleStage::getName()); +void Scene::resetHighlights(const Transaction::HighlightResets& transactions) { + auto outlineStage = getStage(HighlightStage::getName()); for (auto& transaction : transactions) { const auto& selectionName = std::get<0>(transaction); const auto& newStyle = std::get<1>(transaction); - auto outlineId = outlineStage->getOutlineIdBySelection(selectionName); + auto outlineId = outlineStage->getHighlightIdBySelection(selectionName); - if (OutlineStyleStage::isIndexInvalid(outlineId)) { - outlineStage->addOutline(selectionName, newStyle); + if (HighlightStage::isIndexInvalid(outlineId)) { + outlineStage->addHighlight(selectionName, newStyle); } else { - outlineStage->editOutline(outlineId)._style = newStyle; + outlineStage->editHighlight(outlineId)._style = newStyle; } } } -void Scene::removeOutlines(const Transaction::OutlineRemoves& transactions) { - auto outlineStage = getStage(OutlineStyleStage::getName()); +void Scene::removeHighlights(const Transaction::HighlightRemoves& transactions) { + auto outlineStage = getStage(HighlightStage::getName()); for (auto& selectionName : transactions) { - auto outlineId = outlineStage->getOutlineIdBySelection(selectionName); + auto outlineId = outlineStage->getHighlightIdBySelection(selectionName); - if (!OutlineStyleStage::isIndexInvalid(outlineId)) { - outlineStage->removeOutline(outlineId); + if (!HighlightStage::isIndexInvalid(outlineId)) { + outlineStage->removeHighlight(outlineId); } } } -void Scene::queryOutlines(const Transaction::OutlineQueries& transactions) { - auto outlineStage = getStage(OutlineStyleStage::getName()); +void Scene::queryHighlights(const Transaction::HighlightQueries& transactions) { + auto outlineStage = getStage(HighlightStage::getName()); for (auto& transaction : transactions) { const auto& selectionName = std::get<0>(transaction); const auto& func = std::get<1>(transaction); - auto outlineId = outlineStage->getOutlineIdBySelection(selectionName); + auto outlineId = outlineStage->getHighlightIdBySelection(selectionName); - if (!OutlineStyleStage::isIndexInvalid(outlineId)) { - func(&outlineStage->editOutline(outlineId)._style); + if (!HighlightStage::isIndexInvalid(outlineId)) { + func(&outlineStage->editHighlight(outlineId)._style); } else { func(nullptr); } diff --git a/libraries/render/src/render/Scene.h b/libraries/render/src/render/Scene.h index 38f528aced..4bf38b89cc 100644 --- a/libraries/render/src/render/Scene.h +++ b/libraries/render/src/render/Scene.h @@ -17,7 +17,7 @@ #include "Stage.h" #include "Selection.h" #include "Transition.h" -#include "OutlineStyle.h" +#include "HighlightStyle.h" namespace render { @@ -38,7 +38,7 @@ class Transaction { public: typedef std::function TransitionQueryFunc; - typedef std::function SelectionOutlineQueryFunc; + typedef std::function SelectionHighlightQueryFunc; Transaction() {} ~Transaction() {} @@ -63,9 +63,9 @@ public: // Selection transactions void resetSelection(const Selection& selection); - void resetSelectionOutline(const std::string& selectionName, const OutlineStyle& style = OutlineStyle()); - void removeOutlineFromSelection(const std::string& selectionName); - void querySelectionOutline(const std::string& selectionName, SelectionOutlineQueryFunc func); + void resetSelectionHighlight(const std::string& selectionName, const HighlightStyle& style = HighlightStyle()); + void removeHighlightFromSelection(const std::string& selectionName); + void querySelectionHighlight(const std::string& selectionName, SelectionHighlightQueryFunc func); void merge(const Transaction& transaction); @@ -81,9 +81,9 @@ protected: using TransitionQuery = std::tuple; using TransitionReApply = ItemID; using SelectionReset = Selection; - using OutlineReset = std::tuple; - using OutlineRemove = std::string; - using OutlineQuery = std::tuple; + using HighlightReset = std::tuple; + using HighlightRemove = std::string; + using HighlightQuery = std::tuple; using Resets = std::vector; using Removes = std::vector; @@ -92,9 +92,9 @@ protected: using TransitionQueries = std::vector; using TransitionReApplies = std::vector; using SelectionResets = std::vector; - using OutlineResets = std::vector; - using OutlineRemoves = std::vector; - using OutlineQueries = std::vector; + using HighlightResets = std::vector; + using HighlightRemoves = std::vector; + using HighlightQueries = std::vector; Resets _resetItems; Removes _removedItems; @@ -103,9 +103,9 @@ protected: TransitionQueries _queriedTransitions; TransitionReApplies _reAppliedTransitions; SelectionResets _resetSelections; - OutlineResets _outlineResets; - OutlineRemoves _outlineRemoves; - OutlineQueries _outlineQueries; + HighlightResets _highlightResets; + HighlightRemoves _highlightRemoves; + HighlightQueries _highlightQueries; }; typedef std::queue TransactionQueue; @@ -203,9 +203,9 @@ protected: void transitionItems(const Transaction::TransitionAdds& transactions); void reApplyTransitions(const Transaction::TransitionReApplies& transactions); void queryTransitionItems(const Transaction::TransitionQueries& transactions); - void resetOutlines(const Transaction::OutlineResets& transactions); - void removeOutlines(const Transaction::OutlineRemoves& transactions); - void queryOutlines(const Transaction::OutlineQueries& transactions); + void resetHighlights(const Transaction::HighlightResets& transactions); + void removeHighlights(const Transaction::HighlightRemoves& transactions); + void queryHighlights(const Transaction::HighlightQueries& transactions); void collectSubItems(ItemID parentId, ItemIDs& subItems) const; diff --git a/scripts/developer/utilities/render/debugOutline.js b/scripts/developer/utilities/render/debugHighlight.js similarity index 88% rename from scripts/developer/utilities/render/debugOutline.js rename to scripts/developer/utilities/render/debugHighlight.js index ce32d61e1b..5175761978 100644 --- a/scripts/developer/utilities/render/debugOutline.js +++ b/scripts/developer/utilities/render/debugHighlight.js @@ -1,5 +1,5 @@ // -// debugOutline.js +// debugHighlight.js // developer/utilities/render // // Olivier Prat, created on 08/08/2017. @@ -10,9 +10,9 @@ // // Set up the qml ui -var qml = Script.resolvePath('outline.qml'); +var qml = Script.resolvePath('highlight.qml'); var window = new OverlayWindow({ - title: 'Outline', + title: 'Highlight', source: qml, width: 400, height: 400, @@ -54,7 +54,7 @@ var end2 = { visible: true } -var outlineGroupIndex = 0 +var highlightGroupIndex = 0 var isSelectionAddEnabled = false var isSelectionEnabled = false var renderStates = [{name: "test", end: end}]; @@ -72,18 +72,18 @@ var ray = LaserPointers.createLaserPointer({ function getSelectionName() { var selectionName = "contextOverlayHighlightList" - if (outlineGroupIndex>0) { - selectionName += outlineGroupIndex + if (highlightGroupIndex>0) { + selectionName += highlightGroupIndex } return selectionName } function fromQml(message) { tokens = message.split(' ') - print("Received '"+message+"' from outline.qml") - if (tokens[0]=="outline") { - outlineGroupIndex = parseInt(tokens[1]) - print("Switching to outline group "+outlineGroupIndex) + print("Received '"+message+"' from hightlight.qml") + if (tokens[0]=="highlight") { + highlightGroupIndex = parseInt(tokens[1]) + print("Switching to highlight group "+highlightGroupIndex) } else if (tokens[0]=="pick") { isSelectionEnabled = tokens[1]=='true' print("Ray picking set to "+isSelectionEnabled.toString()) @@ -143,7 +143,7 @@ function update(deltaTime) { selectedID = prevID selectedType = prevType Selection.addToSelectedItemsList(selectionName, selectedType, selectedID) - print("OUTLINE " + outlineGroupIndex + " picked type: " + result.type + ", id: " + result.objectID); + print("HIGHLIGHT " + highlightGroupIndex + " picked type: " + result.type + ", id: " + result.objectID); } } else { if (prevID != 0 && !isSelectionAddEnabled) { diff --git a/scripts/developer/utilities/render/outline.qml b/scripts/developer/utilities/render/highlight.qml similarity index 88% rename from scripts/developer/utilities/render/outline.qml rename to scripts/developer/utilities/render/highlight.qml index 8269ea830e..eb2c66b275 100644 --- a/scripts/developer/utilities/render/outline.qml +++ b/scripts/developer/utilities/render/highlight.qml @@ -1,5 +1,5 @@ // -// outline.qml +// highlight.qml // developer/utilities/render // // Olivier Prat, created on 08/08/2017. @@ -11,7 +11,7 @@ import QtQuick 2.7 import QtQuick.Controls 1.4 import QtQuick.Layouts 1.3 -import "outlinePage" +import "highlightPage" import "qrc:///qml/styles-uit" import "qrc:///qml/controls-uit" as HifiControls @@ -21,7 +21,7 @@ Rectangle { color: hifi.colors.baseGray; anchors.margins: hifi.dimensions.contentMargin.x - property var debugConfig: Render.getConfig("RenderMainView.OutlineDebug") + property var debugConfig: Render.getConfig("RenderMainView.HighlightDebug") signal sendToScript(var message); Column { @@ -65,15 +65,15 @@ Rectangle { height: 400 onCurrentIndexChanged: { - sendToScript("outline "+currentIndex) + sendToScript("highlight "+currentIndex) } Repeater { model: [ 0, 1, 2, 3 ] Tab { title: "Outl."+modelData - OutlinePage { - outlineIndex: modelData + HighlightPage { + highlightIndex: modelData } } } diff --git a/scripts/developer/utilities/render/outlinePage/OutlinePage.qml b/scripts/developer/utilities/render/highlightPage/HighlightPage.qml similarity index 96% rename from scripts/developer/utilities/render/outlinePage/OutlinePage.qml rename to scripts/developer/utilities/render/highlightPage/HighlightPage.qml index ff1d7fa23b..5669f90628 100644 --- a/scripts/developer/utilities/render/outlinePage/OutlinePage.qml +++ b/scripts/developer/utilities/render/highlightPage/HighlightPage.qml @@ -1,5 +1,5 @@ // -// outlinePage.qml +// highlightPage.qml // developer/utilities/render // // Olivier Prat, created on 08/08/2017. @@ -17,8 +17,8 @@ import "qrc:///qml/controls-uit" as HifiControls Rectangle { id: root - property var outlineIndex: 0 - property var drawConfig: Render.getConfig("RenderMainView.OutlineEffect"+outlineIndex) + property var highlightIndex: 0 + property var drawConfig: Render.getConfig("RenderMainView.HighlightEffect"+highlightIndex) HifiConstants { id: hifi;} anchors.margins: hifi.dimensions.contentMargin.x diff --git a/scripts/developer/utilities/render/highlightPage/qmldir b/scripts/developer/utilities/render/highlightPage/qmldir new file mode 100644 index 0000000000..bb3de24b84 --- /dev/null +++ b/scripts/developer/utilities/render/highlightPage/qmldir @@ -0,0 +1 @@ +HighlightPage 1.0 HighlightPage.qml \ No newline at end of file diff --git a/scripts/developer/utilities/render/outlinePage/qmldir b/scripts/developer/utilities/render/outlinePage/qmldir deleted file mode 100644 index 56f5d45414..0000000000 --- a/scripts/developer/utilities/render/outlinePage/qmldir +++ /dev/null @@ -1 +0,0 @@ -OutlinePage 1.0 OutlinePage.qml \ No newline at end of file