Added scale and duration debug parameters in debugFade.qml

This commit is contained in:
Olivier Prat 2017-06-13 15:31:04 +02:00
parent 24d45e0f5b
commit ace301945c
6 changed files with 59 additions and 25 deletions

View file

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

View file

@ -7,8 +7,10 @@
#include <render/ShapePipeline.h>
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<TextureCache>()->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;
}

View file

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

View file

@ -51,8 +51,16 @@ extern void initDeferredPipelines(render::ShapePlumber& plumber);
void RenderDeferredTask::configure(const Config& config)
{
DependencyManager::get<FadeEffect>()->setDebugEnabled(config.debugFade);
DependencyManager::get<FadeEffect>()->setDebugFadePercent(config.debugFadePercent);
const float SCALE_MIN = 0.01f;
const float SCALE_MAX = 5.f;
auto fadeEffect = DependencyManager::get<FadeEffect>();
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) {

View file

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

View file

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