Renamed outline to highlight

This commit is contained in:
Olivier Prat 2017-11-07 11:07:25 +01:00
parent 84be026e0b
commit 3cc445ff02
23 changed files with 403 additions and 402 deletions

1
.gitignore vendored
View file

@ -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

View file

@ -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;

View file

@ -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)$>

View file

@ -1,7 +1,7 @@
<@include gpu/Config.slh@>
<$VERSION_HEADER$>
<!
// Outline.slh
// Highlight.slh
// fragment shader
//
// Created by Olivier Prat on 9/7/17.
@ -13,14 +13,14 @@
<@include DeferredTransform.slh@>
<$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<params._blurKernelSize ; x++) {
if (uv.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;

View file

@ -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<OutlineRessources>();
PrepareDrawHighlight::PrepareDrawHighlight() {
_ressources = std::make_shared<HighlightRessources>();
}
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<gpu::Buffer>(sizeof(render::ItemBound));
}
auto outlineStage = renderContext->_scene->getStage<render::OutlineStyleStage>(render::OutlineStyleStage::getName());
auto outlineId = _sharedParameters->_outlineIds[_outlineIndex];
auto highlightStage = renderContext->_scene->getStage<render::HighlightStage>(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>(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>(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<GeometryCache>()->allocateID();
}
DebugOutline::~DebugOutline() {
DebugHighlight::~DebugHighlight() {
auto geometryCache = DependencyManager::get<GeometryCache>();
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<GeometryCache>();
@ -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>(render::OutlineStyleStage::getName());
void SelectionToHighlight::run(const render::RenderContextPointer& renderContext, Outputs& outputs) {
auto highlightStage = renderContext->_scene->getStage<render::HighlightStage>(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<Inputs>(0).get<RenderFetchCullSortTask::BucketList>();
const auto sceneFrameBuffer = inputs.getN<Inputs>(1);
const auto primaryFramebuffer = inputs.getN<Inputs>(2);
@ -477,53 +478,53 @@ void DrawOutlineTask::build(JobModel& task, const render::Varying& inputs, rende
initMaskPipelines(*shapePlumber, state);
}
auto sharedParameters = std::make_shared<OutlineSharedParameters>();
auto sharedParameters = std::make_shared<HighlightSharedParameters>();
const auto outlineSelectionNames = task.addJob<SelectionToOutline>("SelectionToOutline", sharedParameters);
const auto highlightSelectionNames = task.addJob<SelectionToHighlight>("SelectionToHighlight", sharedParameters);
// Prepare for outline group rendering.
const auto outlineRessources = task.addJob<PrepareDrawOutline>("PrepareOutline", primaryFramebuffer);
render::Varying outline0Rect;
// Prepare for highlight group rendering.
const auto highlightRessources = task.addJob<PrepareDrawHighlight>("PrepareHighlight", primaryFramebuffer);
render::Varying highlight0Rect;
for (auto i = 0; i < OutlineSharedParameters::MAX_OUTLINE_COUNT; i++) {
const auto selectionName = task.addJob<ExtractSelectionName>("ExtractSelectionName", outlineSelectionNames, i);
for (auto i = 0; i < HighlightSharedParameters::MAX_HIGHLIGHT_COUNT; i++) {
const auto selectionName = task.addJob<ExtractSelectionName>("ExtractSelectionName", highlightSelectionNames, i);
const auto groupItems = addSelectItemJobs(task, selectionName, items);
const auto outlinedItemIDs = task.addJob<render::MetaToSubItems>("OutlineMetaToSubItemIDs", groupItems);
const auto outlinedItems = task.addJob<render::IDsToBounds>("OutlineMetaToSubItems", outlinedItemIDs);
const auto highlightedItemIDs = task.addJob<render::MetaToSubItems>("HighlightMetaToSubItemIDs", groupItems);
const auto highlightedItems = task.addJob<render::IDsToBounds>("HighlightMetaToSubItems", highlightedItemIDs);
// Sort
const auto sortedPipelines = task.addJob<render::PipelineSortShapes>("OutlinePipelineSort", outlinedItems);
const auto sortedBounds = task.addJob<render::DepthSortShapes>("OutlineDepthSort", sortedPipelines);
const auto sortedPipelines = task.addJob<render::PipelineSortShapes>("HighlightPipelineSort", highlightedItems);
const auto sortedBounds = task.addJob<render::DepthSortShapes>("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<DrawOutlineMask>(name, drawMaskInputs, i, shapePlumber, sharedParameters);
const auto drawMaskInputs = DrawHighlightMask::Inputs(sortedBounds, highlightRessources).asVarying();
const auto highlightedRect = task.addJob<DrawHighlightMask>(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<DrawOutline>(name, drawOutlineInputs, i, sharedParameters);
const auto drawHighlightInputs = DrawHighlight::Inputs(deferredFrameTransform, highlightRessources, sceneFrameBuffer, highlightedRect).asVarying();
task.addJob<DrawHighlight>(name, drawHighlightInputs, i, sharedParameters);
}
// Debug outline
const auto debugInputs = DebugOutline::Inputs(outlineRessources, const_cast<const render::Varying&>(outline0Rect)).asVarying();
task.addJob<DebugOutline>("OutlineDebug", debugInputs);
// Debug highlight
const auto debugInputs = DebugHighlight::Inputs(highlightRessources, const_cast<const render::Varying&>(highlight0Rect)).asVarying();
task.addJob<DebugHighlight>("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);

View file

@ -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 <render/Engine.h>
#include <render/OutlineStyleStage.h>
#include <render/HighlightStage.h>
#include <render/RenderFetchCullSortTask.h>
#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<OutlineRessources>;
using HighlightRessourcesPointer = std::shared_ptr<HighlightRessources>;
class OutlineSharedParameters {
class HighlightSharedParameters {
public:
enum {
MAX_OUTLINE_COUNT = 8
MAX_HIGHLIGHT_COUNT = 8
};
OutlineSharedParameters();
HighlightSharedParameters();
std::array<render::OutlineStyleStage::Index, MAX_OUTLINE_COUNT> _outlineIds;
std::array<render::HighlightStage::Index, MAX_HIGHLIGHT_COUNT> _highlightIds;
static float getBlurPixelWidth(const render::OutlineStyle& style, int frameBufferHeight);
static float getBlurPixelWidth(const render::HighlightStyle& style, int frameBufferHeight);
};
using OutlineSharedParametersPointer = std::shared_ptr<OutlineSharedParameters>;
using HighlightSharedParametersPointer = std::shared_ptr<HighlightSharedParameters>;
class PrepareDrawOutline {
class PrepareDrawHighlight {
public:
using Inputs = gpu::FramebufferPointer;
using Outputs = OutlineRessourcesPointer;
using JobModel = render::Job::ModelIO<PrepareDrawOutline, Inputs, Outputs>;
using Outputs = HighlightRessourcesPointer;
using JobModel = render::Job::ModelIO<PrepareDrawHighlight, Inputs, Outputs>;
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<std::string>;
using JobModel = render::Job::ModelO<SelectionToOutline, Outputs>;
using JobModel = render::Job::ModelO<SelectionToHighlight, Outputs>;
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, Inputs, Outputs>;
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<render::ShapeBounds, OutlineRessourcesPointer>;
using Inputs = render::VaryingSet2<render::ShapeBounds, HighlightRessourcesPointer>;
using Outputs = glm::ivec4;
using JobModel = render::Job::ModelIO<DrawOutlineMask, Inputs, Outputs>;
using JobModel = render::Job::ModelIO<DrawHighlightMask, Inputs, Outputs>;
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<DeferredFrameTransformPointer, OutlineRessourcesPointer, DeferredFramebufferPointer, glm::ivec4>;
using Inputs = render::VaryingSet4<DeferredFrameTransformPointer, HighlightRessourcesPointer, DeferredFramebufferPointer, glm::ivec4>;
using Config = render::Job::Config;
using JobModel = render::Job::ModelI<DrawOutline, Inputs, Config>;
using JobModel = render::Job::ModelI<DrawHighlight, Inputs, Config>;
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<OutlineParameters>;
using HighlightConfigurationBuffer = gpu::StructBuffer<HighlightParameters>;
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<OutlineRessourcesPointer, glm::ivec4>;
using Config = DebugOutlineConfig;
using JobModel = render::Job::ModelI<DebugOutline, Inputs, Config>;
using Inputs = render::VaryingSet2<HighlightRessourcesPointer, glm::ivec4>;
using Config = DebugHighlightConfig;
using JobModel = render::Job::ModelI<DebugHighlight, Inputs, Config>;
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<RenderFetchCullSortTask::BucketList, DeferredFramebufferPointer, gpu::FramebufferPointer, DeferredFrameTransformPointer>;
using Config = render::Task::Config;
using JobModel = render::Task::ModelI<DrawOutlineTask, Inputs, Config>;
using JobModel = render::Task::ModelI<DrawHighlightTask, Inputs, Config>;
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

View file

@ -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)$>

View file

@ -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;

View file

@ -42,7 +42,7 @@
#include "ToneMappingEffect.h"
#include "SubsurfaceScattering.h"
#include "DrawHaze.h"
#include "OutlineEffect.h"
#include "HighlightEffect.h"
#include <gpu/StandardShaderLib.h>
@ -183,15 +183,15 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
const auto toneMappingInputs = ToneMappingDeferred::Inputs(lightingFramebuffer, primaryFramebuffer).asVarying();
task.addJob<ToneMappingDeferred>("ToneMapping", toneMappingInputs);
const auto outlineRangeTimer = task.addJob<BeginGPURangeTimer>("BeginOutlineRangeTimer", "Outline");
const auto outlineRangeTimer = task.addJob<BeginGPURangeTimer>("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<DrawOutlineTask>("DrawOutline", outlineInputs);
const auto outlineInputs = DrawHighlightTask::Inputs(items.get0(), deferredFramebuffer, primaryFramebuffer, deferredFrameTransform).asVarying();
task.addJob<DrawHighlightTask>("DrawHighlight", outlineInputs);
task.addJob<EndGPURangeTimer>("OutlineRangeTimer", outlineRangeTimer);
task.addJob<EndGPURangeTimer>("HighlightRangeTimer", outlineRangeTimer);
{ // DEbug the bounds of the rendered items, still look at the zbuffer
task.addJob<DrawBounds>("DrawMetaBounds", metas);

View file

@ -15,7 +15,7 @@
#include "BackgroundStage.h"
#include "HazeStage.h"
#include <render/TransitionStage.h>
#include <render/OutlineStyleStage.h>
#include <render/HighlightStage.h>
#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>("BackgroundStageSetup");
task.addJob<HazeStageSetup>("HazeStageSetup");
task.addJob<render::TransitionStageSetup>("TransitionStageSetup");
task.addJob<render::OutlineStyleStageSetup>("OutlineStyleStageSetup");
task.addJob<render::HighlightStageSetup>("HighlightStageSetup");
task.addJob<DefaultLightingSetup>("DefaultLightingSetup");

View file

@ -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<HighlightStage>();
renderContext->_scene->resetStage(HighlightStage::getName(), stage);
}
}

View file

@ -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<Highlight>;
static std::string _name;
Highlights _highlights;
HighlightIdList _activeHighlightIds;
};
using HighlightStagePointer = std::shared_ptr<HighlightStage>;
class HighlightStageSetup {
public:
using JobModel = render::Job::Model<HighlightStageSetup>;
HighlightStageSetup();
void run(const RenderContextPointer& renderContext);
protected:
};
}
#endif // hifi_render_utils_HighlightStage_h

View file

@ -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 <glm/vec3.hpp>
@ -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
#endif // hifi_render_utils_HighlightStyle_h

View file

@ -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<OutlineStyleStage>();
renderContext->_scene->resetStage(OutlineStyleStage::getName(), stage);
}
}

View file

@ -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<Outline>;
static std::string _name;
Outlines _outlines;
OutlineIdList _activeOutlineIds;
};
using OutlineStyleStagePointer = std::shared_ptr<OutlineStyleStage>;
class OutlineStyleStageSetup {
public:
using JobModel = render::Job::Model<OutlineStyleStageSetup>;
OutlineStyleStageSetup();
void run(const RenderContextPointer& renderContext);
protected:
};
}
#endif // hifi_render_utils_outlinestage_h

View file

@ -14,7 +14,7 @@
#include <gpu/Batch.h>
#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>(OutlineStyleStage::getName());
void Scene::resetHighlights(const Transaction::HighlightResets& transactions) {
auto outlineStage = getStage<HighlightStage>(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>(OutlineStyleStage::getName());
void Scene::removeHighlights(const Transaction::HighlightRemoves& transactions) {
auto outlineStage = getStage<HighlightStage>(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>(OutlineStyleStage::getName());
void Scene::queryHighlights(const Transaction::HighlightQueries& transactions) {
auto outlineStage = getStage<HighlightStage>(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);
}

View file

@ -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<void(ItemID, const Transition*)> TransitionQueryFunc;
typedef std::function<void(OutlineStyle const*)> SelectionOutlineQueryFunc;
typedef std::function<void(HighlightStyle const*)> 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<ItemID, TransitionQueryFunc>;
using TransitionReApply = ItemID;
using SelectionReset = Selection;
using OutlineReset = std::tuple<std::string, OutlineStyle>;
using OutlineRemove = std::string;
using OutlineQuery = std::tuple<std::string, SelectionOutlineQueryFunc>;
using HighlightReset = std::tuple<std::string, HighlightStyle>;
using HighlightRemove = std::string;
using HighlightQuery = std::tuple<std::string, SelectionHighlightQueryFunc>;
using Resets = std::vector<Reset>;
using Removes = std::vector<Remove>;
@ -92,9 +92,9 @@ protected:
using TransitionQueries = std::vector<TransitionQuery>;
using TransitionReApplies = std::vector<TransitionReApply>;
using SelectionResets = std::vector<SelectionReset>;
using OutlineResets = std::vector<OutlineReset>;
using OutlineRemoves = std::vector<OutlineRemove>;
using OutlineQueries = std::vector<OutlineQuery>;
using HighlightResets = std::vector<HighlightReset>;
using HighlightRemoves = std::vector<HighlightRemove>;
using HighlightQueries = std::vector<HighlightQuery>;
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<Transaction> 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;

View file

@ -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) {

View file

@ -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
}
}
}

View file

@ -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

View file

@ -0,0 +1 @@
HighlightPage 1.0 HighlightPage.qml

View file

@ -1 +0,0 @@
OutlinePage 1.0 OutlinePage.qml