From 392a99f038cf7367dba134d086d72d6c92b2201a Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Wed, 9 Aug 2017 19:18:16 +0200 Subject: [PATCH] Added some fill parameters. Still need to fix issues with blur changing with screen aspect ratio --- libraries/render-utils/src/Outline.slf | 38 ++++--- libraries/render-utils/src/OutlineEffect.cpp | 8 +- libraries/render-utils/src/OutlineEffect.h | 10 ++ libraries/render-utils/src/Outline_shared.slh | 3 + .../utilities/render/debugOutline.js | 4 +- .../developer/utilities/render/outline.qml | 101 +++++++++++++----- 6 files changed, 119 insertions(+), 45 deletions(-) diff --git a/libraries/render-utils/src/Outline.slf b/libraries/render-utils/src/Outline.slf index 1aec1efd5a..acb79184fe 100644 --- a/libraries/render-utils/src/Outline.slf +++ b/libraries/render-utils/src/Outline.slf @@ -28,15 +28,25 @@ const float FAR_DISTANCE = 1.0; void main(void) { float outlinedDepth = texture(outlinedDepthMap, varTexCoord0).x; + float intensity = 0.0; + if (outlinedDepth < FAR_DISTANCE) { // We're not on the far plane so we are on the outlined object, thus no outline to do! - discard; - } - //float sceneDepth = texture(sceneDepthMap, varTexCoord0).x; - float outlineIntensity = 0.0; - float weight = 0.0; - { + // But maybe we need to fill the interior + if (params._fillOpacityUnoccluded>1e-3 && params._fillOpacityUnoccluded>1e-3) { + // Are we occluded? + float sceneDepth = texture(sceneDepthMap, varTexCoord0).x; + if (sceneDepth < outlinedDepth) { + intensity = params._fillOpacityOccluded; + } else { + intensity = params._fillOpacityUnoccluded; + } + } else { + discard; + } + } else { + float weight = 0.0; const float deltaUv = params._size / BLUR_KERNEL_SIZE; vec2 uv; vec2 startUv = varTexCoord0 - vec2(params._size, params._size) / 2.0; @@ -52,7 +62,7 @@ void main(void) { if (uv.x>=0.0 && uv.x<=1.0) { outlinedDepth = texture(outlinedDepthMap, uv).x; - outlineIntensity += (outlinedDepth < FAR_DISTANCE) ? 1.0 : 0.0; + intensity += (outlinedDepth < FAR_DISTANCE) ? 1.0 : 0.0; weight += 1.f; } uv.x += deltaUv; @@ -60,12 +70,14 @@ void main(void) { } } - outlineIntensity /= weight; + intensity /= weight; + + if (intensity < 1e-3) { + discard; + } + + intensity = min(1.0, intensity / params._threshold) * params._intensity; } - if (outlineIntensity < 1e-3) { - discard; - } - outlineIntensity = min(1.0, outlineIntensity * params._intensity); - outFragColor = vec4(params._color.rgb, outlineIntensity); + outFragColor = vec4(params._color.rgb, intensity); } diff --git a/libraries/render-utils/src/OutlineEffect.cpp b/libraries/render-utils/src/OutlineEffect.cpp index c91f10001d..1012067851 100644 --- a/libraries/render-utils/src/OutlineEffect.cpp +++ b/libraries/render-utils/src/OutlineEffect.cpp @@ -131,7 +131,10 @@ DrawOutline::DrawOutline() { void DrawOutline::configure(const Config& config) { _color = config.color; _size = config.width / 1024.f; - _intensity = config.intensity * 10.f; + _fillOpacityUnoccluded = config.fillOpacityUnoccluded; + _fillOpacityOccluded = config.fillOpacityOccluded; + _threshold = config.glow ? 1.f : 0.f; + _intensity = config.intensity * (config.glow ? 2.f : 1.f); } void DrawOutline::run(const render::RenderContextPointer& renderContext, const Inputs& inputs) { @@ -150,6 +153,9 @@ void DrawOutline::run(const render::RenderContextPointer& renderContext, const I configuration._color = _color; configuration._size = _size; configuration._intensity = _intensity; + configuration._fillOpacityUnoccluded = _fillOpacityUnoccluded; + configuration._fillOpacityOccluded = _fillOpacityOccluded; + configuration._threshold = _threshold; } gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { diff --git a/libraries/render-utils/src/OutlineEffect.h b/libraries/render-utils/src/OutlineEffect.h index fc8a715a53..d0c586dafc 100644 --- a/libraries/render-utils/src/OutlineEffect.h +++ b/libraries/render-utils/src/OutlineEffect.h @@ -75,11 +75,15 @@ private: class DrawOutlineConfig : public render::Job::Config { Q_OBJECT + Q_PROPERTY(bool glow MEMBER glow NOTIFY dirty) Q_PROPERTY(float width MEMBER width NOTIFY dirty) Q_PROPERTY(float intensity MEMBER intensity NOTIFY dirty) Q_PROPERTY(float colorR READ getColorR WRITE setColorR NOTIFY dirty) Q_PROPERTY(float colorG READ getColorG WRITE setColorG NOTIFY dirty) Q_PROPERTY(float colorB READ getColorB WRITE setColorB NOTIFY dirty) + Q_PROPERTY(float fillOpacityUnoccluded MEMBER fillOpacityUnoccluded NOTIFY dirty) + Q_PROPERTY(float fillOpacityOccluded MEMBER fillOpacityOccluded NOTIFY dirty) + public: void setColorR(float value) { color.r = value; emit dirty(); } @@ -94,6 +98,9 @@ public: glm::vec3 color{ 1.f, 0.7f, 0.2f }; float width{ 5.f }; float intensity{ 1.f }; + float fillOpacityUnoccluded{ 0.35f }; + float fillOpacityOccluded{ 0.1f }; + bool glow{ false }; signals: void dirty(); @@ -128,6 +135,9 @@ private: glm::vec3 _color; float _size; float _intensity; + float _fillOpacityUnoccluded; + float _fillOpacityOccluded; + float _threshold; }; class DebugOutlineConfig : public render::Job::Config { diff --git a/libraries/render-utils/src/Outline_shared.slh b/libraries/render-utils/src/Outline_shared.slh index 602e15f8e7..27c9882815 100644 --- a/libraries/render-utils/src/Outline_shared.slh +++ b/libraries/render-utils/src/Outline_shared.slh @@ -10,6 +10,9 @@ struct OutlineParameters VEC3 _color; float _size; float _intensity; + float _fillOpacityUnoccluded; + float _fillOpacityOccluded; + float _threshold; }; // <@if 1@> diff --git a/scripts/developer/utilities/render/debugOutline.js b/scripts/developer/utilities/render/debugOutline.js index 05b7ffbbc9..e333ab5869 100644 --- a/scripts/developer/utilities/render/debugOutline.js +++ b/scripts/developer/utilities/render/debugOutline.js @@ -14,7 +14,7 @@ var qml = Script.resolvePath('outline.qml'); var window = new OverlayWindow({ title: 'Outline', source: qml, - width: 250, - height: 250, + width: 285, + height: 370, }); window.closed.connect(function() { Script.stop(); }); \ No newline at end of file diff --git a/scripts/developer/utilities/render/outline.qml b/scripts/developer/utilities/render/outline.qml index 7ed3b6a2bb..321dd9271b 100644 --- a/scripts/developer/utilities/render/outline.qml +++ b/scripts/developer/utilities/render/outline.qml @@ -35,6 +35,13 @@ Item { root.debugConfig["viewOutlinedDepth"] = checked; } } + CheckBox { + text: "Glow" + checked: root.drawConfig["glow"] + onCheckedChanged: { + root.drawConfig["glow"] = checked; + } + } ConfigSlider { label: "Width" integral: false @@ -42,7 +49,7 @@ Item { property: "width" max: 15.0 min: 0.0 - width: 230 + width: 280 } ConfigSlider { label: "Intensity" @@ -51,34 +58,70 @@ Item { property: "intensity" max: 1.0 min: 0.0 - width: 230 - } - ConfigSlider { - label: "Color R" - integral: false - config: root.drawConfig - property: "colorR" - max: 1.0 - min: 0.0 - width: 230 - } - ConfigSlider { - label: "Color G" - integral: false - config: root.drawConfig - property: "colorG" - max: 1.0 - min: 0.0 - width: 230 - } - ConfigSlider { - label: "Color B" - integral: false - config: root.drawConfig - property: "colorB" - max: 1.0 - min: 0.0 - width: 230 + width: 280 } + + GroupBox { + title: "Color" + width: 280 + Column { + spacing: 8 + + ConfigSlider { + label: "Red" + integral: false + config: root.drawConfig + property: "colorR" + max: 1.0 + min: 0.0 + width: 270 + } + ConfigSlider { + label: "Green" + integral: false + config: root.drawConfig + property: "colorG" + max: 1.0 + min: 0.0 + width: 270 + } + ConfigSlider { + label: "Blue" + integral: false + config: root.drawConfig + property: "colorB" + max: 1.0 + min: 0.0 + width: 270 + } + } + } + + GroupBox { + title: "Fill Opacity" + width: 280 + Column { + spacing: 8 + + ConfigSlider { + label: "Unoccluded" + integral: false + config: root.drawConfig + property: "fillOpacityUnoccluded" + max: 1.0 + min: 0.0 + width: 270 + } + ConfigSlider { + label: "Occluded" + integral: false + config: root.drawConfig + property: "fillOpacityOccluded" + max: 1.0 + min: 0.0 + width: 270 + } + } + } } }