Added some fill parameters. Still need to fix issues with blur changing with screen aspect ratio

This commit is contained in:
Olivier Prat 2017-08-09 19:18:16 +02:00
parent 0f2c41b009
commit 392a99f038
6 changed files with 119 additions and 45 deletions

View file

@ -28,15 +28,25 @@ const float FAR_DISTANCE = 1.0;
void main(void) { void main(void) {
float outlinedDepth = texture(outlinedDepthMap, varTexCoord0).x; float outlinedDepth = texture(outlinedDepthMap, varTexCoord0).x;
float intensity = 0.0;
if (outlinedDepth < FAR_DISTANCE) { if (outlinedDepth < FAR_DISTANCE) {
// We're not on the far plane so we are on the outlined object, thus no outline to do! // We're not on the far plane so we are on the outlined object, thus no outline to do!
// 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; discard;
} }
} else {
//float sceneDepth = texture(sceneDepthMap, varTexCoord0).x;
float outlineIntensity = 0.0;
float weight = 0.0; float weight = 0.0;
{
const float deltaUv = params._size / BLUR_KERNEL_SIZE; const float deltaUv = params._size / BLUR_KERNEL_SIZE;
vec2 uv; vec2 uv;
vec2 startUv = varTexCoord0 - vec2(params._size, params._size) / 2.0; 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) if (uv.x>=0.0 && uv.x<=1.0)
{ {
outlinedDepth = texture(outlinedDepthMap, uv).x; outlinedDepth = texture(outlinedDepthMap, uv).x;
outlineIntensity += (outlinedDepth < FAR_DISTANCE) ? 1.0 : 0.0; intensity += (outlinedDepth < FAR_DISTANCE) ? 1.0 : 0.0;
weight += 1.f; weight += 1.f;
} }
uv.x += deltaUv; uv.x += deltaUv;
@ -60,12 +70,14 @@ void main(void) {
} }
} }
outlineIntensity /= weight; intensity /= weight;
}
if (outlineIntensity < 1e-3) { if (intensity < 1e-3) {
discard; discard;
} }
outlineIntensity = min(1.0, outlineIntensity * params._intensity);
outFragColor = vec4(params._color.rgb, outlineIntensity); intensity = min(1.0, intensity / params._threshold) * params._intensity;
}
outFragColor = vec4(params._color.rgb, intensity);
} }

View file

@ -131,7 +131,10 @@ DrawOutline::DrawOutline() {
void DrawOutline::configure(const Config& config) { void DrawOutline::configure(const Config& config) {
_color = config.color; _color = config.color;
_size = config.width / 1024.f; _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) { 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._color = _color;
configuration._size = _size; configuration._size = _size;
configuration._intensity = _intensity; configuration._intensity = _intensity;
configuration._fillOpacityUnoccluded = _fillOpacityUnoccluded;
configuration._fillOpacityOccluded = _fillOpacityOccluded;
configuration._threshold = _threshold;
} }
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {

View file

@ -75,11 +75,15 @@ private:
class DrawOutlineConfig : public render::Job::Config { class DrawOutlineConfig : public render::Job::Config {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool glow MEMBER glow NOTIFY dirty)
Q_PROPERTY(float width MEMBER width NOTIFY dirty) Q_PROPERTY(float width MEMBER width NOTIFY dirty)
Q_PROPERTY(float intensity MEMBER intensity NOTIFY dirty) Q_PROPERTY(float intensity MEMBER intensity NOTIFY dirty)
Q_PROPERTY(float colorR READ getColorR WRITE setColorR 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 colorG READ getColorG WRITE setColorG NOTIFY dirty)
Q_PROPERTY(float colorB READ getColorB WRITE setColorB 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: public:
void setColorR(float value) { color.r = value; emit dirty(); } void setColorR(float value) { color.r = value; emit dirty(); }
@ -94,6 +98,9 @@ public:
glm::vec3 color{ 1.f, 0.7f, 0.2f }; glm::vec3 color{ 1.f, 0.7f, 0.2f };
float width{ 5.f }; float width{ 5.f };
float intensity{ 1.f }; float intensity{ 1.f };
float fillOpacityUnoccluded{ 0.35f };
float fillOpacityOccluded{ 0.1f };
bool glow{ false };
signals: signals:
void dirty(); void dirty();
@ -128,6 +135,9 @@ private:
glm::vec3 _color; glm::vec3 _color;
float _size; float _size;
float _intensity; float _intensity;
float _fillOpacityUnoccluded;
float _fillOpacityOccluded;
float _threshold;
}; };
class DebugOutlineConfig : public render::Job::Config { class DebugOutlineConfig : public render::Job::Config {

View file

@ -10,6 +10,9 @@ struct OutlineParameters
VEC3 _color; VEC3 _color;
float _size; float _size;
float _intensity; float _intensity;
float _fillOpacityUnoccluded;
float _fillOpacityOccluded;
float _threshold;
}; };
// <@if 1@> // <@if 1@>

View file

@ -14,7 +14,7 @@ var qml = Script.resolvePath('outline.qml');
var window = new OverlayWindow({ var window = new OverlayWindow({
title: 'Outline', title: 'Outline',
source: qml, source: qml,
width: 250, width: 285,
height: 250, height: 370,
}); });
window.closed.connect(function() { Script.stop(); }); window.closed.connect(function() { Script.stop(); });

View file

@ -35,6 +35,13 @@ Item {
root.debugConfig["viewOutlinedDepth"] = checked; root.debugConfig["viewOutlinedDepth"] = checked;
} }
} }
CheckBox {
text: "Glow"
checked: root.drawConfig["glow"]
onCheckedChanged: {
root.drawConfig["glow"] = checked;
}
}
ConfigSlider { ConfigSlider {
label: "Width" label: "Width"
integral: false integral: false
@ -42,7 +49,7 @@ Item {
property: "width" property: "width"
max: 15.0 max: 15.0
min: 0.0 min: 0.0
width: 230 width: 280
} }
ConfigSlider { ConfigSlider {
label: "Intensity" label: "Intensity"
@ -51,34 +58,70 @@ Item {
property: "intensity" property: "intensity"
max: 1.0 max: 1.0
min: 0.0 min: 0.0
width: 230 width: 280
} }
GroupBox {
title: "Color"
width: 280
Column {
spacing: 8
ConfigSlider { ConfigSlider {
label: "Color R" label: "Red"
integral: false integral: false
config: root.drawConfig config: root.drawConfig
property: "colorR" property: "colorR"
max: 1.0 max: 1.0
min: 0.0 min: 0.0
width: 230 width: 270
} }
ConfigSlider { ConfigSlider {
label: "Color G" label: "Green"
integral: false integral: false
config: root.drawConfig config: root.drawConfig
property: "colorG" property: "colorG"
max: 1.0 max: 1.0
min: 0.0 min: 0.0
width: 230 width: 270
} }
ConfigSlider { ConfigSlider {
label: "Color B" label: "Blue"
integral: false integral: false
config: root.drawConfig config: root.drawConfig
property: "colorB" property: "colorB"
max: 1.0 max: 1.0
min: 0.0 min: 0.0
width: 230 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
}
}
} }
} }
} }