From ace301945c70ecec603ce381e5f4baa023fc2439 Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Tue, 13 Jun 2017 15:31:04 +0200 Subject: [PATCH] Added scale and duration debug parameters in debugFade.qml --- libraries/render-utils/src/Fade.slh | 12 ++------- libraries/render-utils/src/FadeEffect.cpp | 27 +++++++++++-------- libraries/render-utils/src/FadeEffect.h | 9 ++++++- .../render-utils/src/RenderDeferredTask.cpp | 12 +++++++-- .../render-utils/src/RenderDeferredTask.h | 4 +++ scripts/developer/utilities/render/fade.qml | 20 +++++++++++++- 6 files changed, 59 insertions(+), 25 deletions(-) diff --git a/libraries/render-utils/src/Fade.slh b/libraries/render-utils/src/Fade.slh index 38fad9321a..351cbad863 100644 --- a/libraries/render-utils/src/Fade.slh +++ b/libraries/render-utils/src/Fade.slh @@ -20,6 +20,7 @@ uniform vec3 fadeOffset; uniform float fadePercent; +uniform float fadeInvScale; uniform sampler2D fadeMaskMap; vec2 hash2D(vec3 position) { @@ -28,20 +29,11 @@ vec2 hash2D(vec3 position) { float noise3D(vec3 position) { return textureLod(fadeMaskMap, hash2D(position), 0).r; - /*const float ONE_OVER_MAX_POSITIVE_INT = (1.f / 2147483648.f); - int3 iPosition = int3(position); - int position = iPosition.x + (iPosition.y*57) + (iPosition.z*3023); - int bits = (position << 13) ^ position; - int pseudoRandomPositiveInt = (bits * ((bits*bits*15731)+789221)+1376312589) & 0x7fffffff; - float pseudoRandomFloatZeroToOne = ONE_OVER_MAX_POSITIVE_INT * (float)pseudoRandomPositiveInt; - return pseudoRandomFloatZeroToOne;*/ } float evalFadeMask(vec3 position) { - const float FADE_MASK_INV_SCALE = 1.0; - // Do tri-linear interpolation - vec3 noisePosition = position * FADE_MASK_INV_SCALE + fadeOffset; + vec3 noisePosition = position * fadeInvScale + fadeOffset; vec3 noisePositionFloored = floor(noisePosition); vec3 noisePositionFraction = fract(noisePosition); float noiseLowXLowYLowZ = noise3D(noisePositionFloored); diff --git a/libraries/render-utils/src/FadeEffect.cpp b/libraries/render-utils/src/FadeEffect.cpp index dbfcfb780a..71e33549a6 100644 --- a/libraries/render-utils/src/FadeEffect.cpp +++ b/libraries/render-utils/src/FadeEffect.cpp @@ -7,8 +7,10 @@ #include FadeEffect::FadeEffect() : - _isDebugEnabled{ false }, - _debugFadePercent{ 0.f } + _invScale{ 1.f }, + _duration{ 3.f }, + _debugFadePercent{ 0.f }, + _isDebugEnabled{ false } { auto texturePath = PathUtils::resourcesPath() + "images/fadeMask.png"; _fadeMaskMap = DependencyManager::get()->getImageTexture(texturePath, image::TextureUsage::STRICT_TEXTURE); @@ -27,13 +29,14 @@ void FadeEffect::bindPerBatch(gpu::Batch& batch, int fadeMaskMapLocation) const } void FadeEffect::bindPerBatch(gpu::Batch& batch, const gpu::PipelinePointer& pipeline) const { - auto slot = pipeline->getProgram()->getTextures().findLocation("fadeMaskMap"); - batch.setResourceTexture(slot, _fadeMaskMap); + auto program = pipeline->getProgram(); + auto maskMapLocation = program->getTextures().findLocation("fadeMaskMap"); + bindPerBatch(batch, maskMapLocation); } float FadeEffect::computeFadePercent(quint64 startTime) const { float fadeAlpha = 1.0f; - const double INV_FADE_PERIOD = 1.0 / (double)(3 * USECS_PER_SECOND); + const double INV_FADE_PERIOD = 1.0 / (double)(_duration * USECS_PER_SECOND); double fraction = (double)(usecTimestampNow() - startTime) * INV_FADE_PERIOD; if (fraction < 1.0) { fadeAlpha = Interpolate::easeInOutQuad(fraction); @@ -47,11 +50,12 @@ bool FadeEffect::bindPerItem(gpu::Batch& batch, RenderArgs* args, glm::vec3 offs bool FadeEffect::bindPerItem(gpu::Batch& batch, const gpu::Pipeline* pipeline, glm::vec3 offset, quint64 startTime, bool isFading) const { if (isFading || _isDebugEnabled) { - auto& program = pipeline->getProgram(); - auto fadeOffsetLoc = program->getUniforms().findLocation("fadeOffset"); - auto fadePercentLoc = program->getUniforms().findLocation("fadePercent"); + auto& uniforms = pipeline->getProgram()->getUniforms(); + auto fadeScaleLocation = uniforms.findLocation("fadeInvScale"); + auto fadeOffsetLocation = uniforms.findLocation("fadeOffset"); + auto fadePercentLocation = uniforms.findLocation("fadePercent"); - if (fadeOffsetLoc >= 0 && fadePercentLoc >= 0) { + if (fadeScaleLocation >= 0 || fadeOffsetLocation >= 0 || fadePercentLocation>=0) { float percent; // A bit ugly to have the test at every bind... @@ -61,8 +65,9 @@ bool FadeEffect::bindPerItem(gpu::Batch& batch, const gpu::Pipeline* pipeline, g else { percent = _debugFadePercent; } - batch._glUniform1f(fadePercentLoc, percent); - batch._glUniform3f(fadeOffsetLoc, offset.x, offset.y, offset.z); + batch._glUniform1f(fadeScaleLocation, _invScale); + batch._glUniform1f(fadePercentLocation, percent); + batch._glUniform3f(fadeOffsetLocation, offset.x, offset.y, offset.z); } return true; } diff --git a/libraries/render-utils/src/FadeEffect.h b/libraries/render-utils/src/FadeEffect.h index 5be1288120..80e3b79e2e 100644 --- a/libraries/render-utils/src/FadeEffect.h +++ b/libraries/render-utils/src/FadeEffect.h @@ -24,6 +24,12 @@ public: const gpu::TexturePointer getFadeMaskMap() const { return _fadeMaskMap; } + void setScale(float value) { assert(value > 0.f); _invScale = 1.f / value; } + float getScale() const { return 1.f / _invScale; } + + void setDuration(float seconds) { assert(seconds > 0.f); _duration = seconds; } + float getDuration() const { return 1.f / _duration; } + void setDebugEnabled(bool isEnabled) { _isDebugEnabled = isEnabled; } bool isDebugEnabled() const { return _isDebugEnabled; } @@ -42,9 +48,10 @@ public: private: gpu::TexturePointer _fadeMaskMap; + float _invScale; + float _duration; float _debugFadePercent; bool _isDebugEnabled; - }; #endif // hifi_FadeEffect_h diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index ae3dbc058f..a752b18da8 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -51,8 +51,16 @@ extern void initDeferredPipelines(render::ShapePlumber& plumber); void RenderDeferredTask::configure(const Config& config) { - DependencyManager::get()->setDebugEnabled(config.debugFade); - DependencyManager::get()->setDebugFadePercent(config.debugFadePercent); + const float SCALE_MIN = 0.01f; + const float SCALE_MAX = 5.f; + + auto fadeEffect = DependencyManager::get(); + float scale = SCALE_MIN + (SCALE_MAX - SCALE_MIN)*config.fadeScale*config.fadeScale*config.fadeScale; + + fadeEffect->setScale(scale); + fadeEffect->setDuration(config.fadeDuration); + fadeEffect->setDebugEnabled(config.debugFade); + fadeEffect->setDebugFadePercent(config.debugFadePercent); } void RenderDeferredTask::build(JobModel& task, const render::Varying& input, render::Varying& output) { diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index d46f9b53f4..65ae062a9a 100644 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -164,9 +164,13 @@ public: class RenderDeferredTaskConfig : public render::Task::Config { Q_OBJECT + Q_PROPERTY(float fadeScale MEMBER fadeScale NOTIFY dirty) + Q_PROPERTY(float fadeDuration MEMBER fadeDuration NOTIFY dirty) Q_PROPERTY(bool debugFade MEMBER debugFade NOTIFY dirty) Q_PROPERTY(float debugFadePercent MEMBER debugFadePercent NOTIFY dirty) public: + float fadeScale{ 0.5f }; + float fadeDuration{ 3.0f }; float debugFadePercent{ 0.f }; bool debugFade{ false }; diff --git a/scripts/developer/utilities/render/fade.qml b/scripts/developer/utilities/render/fade.qml index 137e45d08d..0a99ca2e7e 100644 --- a/scripts/developer/utilities/render/fade.qml +++ b/scripts/developer/utilities/render/fade.qml @@ -19,7 +19,7 @@ Row { spacing: 8 CheckBox { - text: "Force Fade" + text: "Manual Fade" checked: taskConfig["debugFade"] onCheckedChanged: { taskConfig["debugFade"] = checked } } @@ -36,6 +36,24 @@ Row { min: 0.0 width: 250 } + ConfigSlider { + label: "Scale" + integral: false + config: taskConfig + property: "fadeScale" + max: 1.0 + min: 0.0 + width: 250 + } + ConfigSlider { + label: "Duration" + integral: false + config: taskConfig + property: "fadeDuration" + max: 10.0 + min: 0.1 + width: 250 + } } }