mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 18:56:55 +02:00
Added scale and duration debug parameters in debugFade.qml
This commit is contained in:
parent
24d45e0f5b
commit
ace301945c
6 changed files with 59 additions and 25 deletions
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
uniform vec3 fadeOffset;
|
uniform vec3 fadeOffset;
|
||||||
uniform float fadePercent;
|
uniform float fadePercent;
|
||||||
|
uniform float fadeInvScale;
|
||||||
uniform sampler2D fadeMaskMap;
|
uniform sampler2D fadeMaskMap;
|
||||||
|
|
||||||
vec2 hash2D(vec3 position) {
|
vec2 hash2D(vec3 position) {
|
||||||
|
@ -28,20 +29,11 @@ vec2 hash2D(vec3 position) {
|
||||||
|
|
||||||
float noise3D(vec3 position) {
|
float noise3D(vec3 position) {
|
||||||
return textureLod(fadeMaskMap, hash2D(position), 0).r;
|
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) {
|
float evalFadeMask(vec3 position) {
|
||||||
const float FADE_MASK_INV_SCALE = 1.0;
|
|
||||||
|
|
||||||
// Do tri-linear interpolation
|
// Do tri-linear interpolation
|
||||||
vec3 noisePosition = position * FADE_MASK_INV_SCALE + fadeOffset;
|
vec3 noisePosition = position * fadeInvScale + fadeOffset;
|
||||||
vec3 noisePositionFloored = floor(noisePosition);
|
vec3 noisePositionFloored = floor(noisePosition);
|
||||||
vec3 noisePositionFraction = fract(noisePosition);
|
vec3 noisePositionFraction = fract(noisePosition);
|
||||||
float noiseLowXLowYLowZ = noise3D(noisePositionFloored);
|
float noiseLowXLowYLowZ = noise3D(noisePositionFloored);
|
||||||
|
|
|
@ -7,8 +7,10 @@
|
||||||
#include <render/ShapePipeline.h>
|
#include <render/ShapePipeline.h>
|
||||||
|
|
||||||
FadeEffect::FadeEffect() :
|
FadeEffect::FadeEffect() :
|
||||||
_isDebugEnabled{ false },
|
_invScale{ 1.f },
|
||||||
_debugFadePercent{ 0.f }
|
_duration{ 3.f },
|
||||||
|
_debugFadePercent{ 0.f },
|
||||||
|
_isDebugEnabled{ false }
|
||||||
{
|
{
|
||||||
auto texturePath = PathUtils::resourcesPath() + "images/fadeMask.png";
|
auto texturePath = PathUtils::resourcesPath() + "images/fadeMask.png";
|
||||||
_fadeMaskMap = DependencyManager::get<TextureCache>()->getImageTexture(texturePath, image::TextureUsage::STRICT_TEXTURE);
|
_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 {
|
void FadeEffect::bindPerBatch(gpu::Batch& batch, const gpu::PipelinePointer& pipeline) const {
|
||||||
auto slot = pipeline->getProgram()->getTextures().findLocation("fadeMaskMap");
|
auto program = pipeline->getProgram();
|
||||||
batch.setResourceTexture(slot, _fadeMaskMap);
|
auto maskMapLocation = program->getTextures().findLocation("fadeMaskMap");
|
||||||
|
bindPerBatch(batch, maskMapLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
float FadeEffect::computeFadePercent(quint64 startTime) const {
|
float FadeEffect::computeFadePercent(quint64 startTime) const {
|
||||||
float fadeAlpha = 1.0f;
|
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;
|
double fraction = (double)(usecTimestampNow() - startTime) * INV_FADE_PERIOD;
|
||||||
if (fraction < 1.0) {
|
if (fraction < 1.0) {
|
||||||
fadeAlpha = Interpolate::easeInOutQuad(fraction);
|
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 {
|
bool FadeEffect::bindPerItem(gpu::Batch& batch, const gpu::Pipeline* pipeline, glm::vec3 offset, quint64 startTime, bool isFading) const {
|
||||||
if (isFading || _isDebugEnabled) {
|
if (isFading || _isDebugEnabled) {
|
||||||
auto& program = pipeline->getProgram();
|
auto& uniforms = pipeline->getProgram()->getUniforms();
|
||||||
auto fadeOffsetLoc = program->getUniforms().findLocation("fadeOffset");
|
auto fadeScaleLocation = uniforms.findLocation("fadeInvScale");
|
||||||
auto fadePercentLoc = program->getUniforms().findLocation("fadePercent");
|
auto fadeOffsetLocation = uniforms.findLocation("fadeOffset");
|
||||||
|
auto fadePercentLocation = uniforms.findLocation("fadePercent");
|
||||||
|
|
||||||
if (fadeOffsetLoc >= 0 && fadePercentLoc >= 0) {
|
if (fadeScaleLocation >= 0 || fadeOffsetLocation >= 0 || fadePercentLocation>=0) {
|
||||||
float percent;
|
float percent;
|
||||||
|
|
||||||
// A bit ugly to have the test at every bind...
|
// 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 {
|
else {
|
||||||
percent = _debugFadePercent;
|
percent = _debugFadePercent;
|
||||||
}
|
}
|
||||||
batch._glUniform1f(fadePercentLoc, percent);
|
batch._glUniform1f(fadeScaleLocation, _invScale);
|
||||||
batch._glUniform3f(fadeOffsetLoc, offset.x, offset.y, offset.z);
|
batch._glUniform1f(fadePercentLocation, percent);
|
||||||
|
batch._glUniform3f(fadeOffsetLocation, offset.x, offset.y, offset.z);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,12 @@ public:
|
||||||
|
|
||||||
const gpu::TexturePointer getFadeMaskMap() const { return _fadeMaskMap; }
|
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; }
|
void setDebugEnabled(bool isEnabled) { _isDebugEnabled = isEnabled; }
|
||||||
bool isDebugEnabled() const { return _isDebugEnabled; }
|
bool isDebugEnabled() const { return _isDebugEnabled; }
|
||||||
|
|
||||||
|
@ -42,9 +48,10 @@ public:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
gpu::TexturePointer _fadeMaskMap;
|
gpu::TexturePointer _fadeMaskMap;
|
||||||
|
float _invScale;
|
||||||
|
float _duration;
|
||||||
float _debugFadePercent;
|
float _debugFadePercent;
|
||||||
bool _isDebugEnabled;
|
bool _isDebugEnabled;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_FadeEffect_h
|
#endif // hifi_FadeEffect_h
|
||||||
|
|
|
@ -51,8 +51,16 @@ extern void initDeferredPipelines(render::ShapePlumber& plumber);
|
||||||
|
|
||||||
void RenderDeferredTask::configure(const Config& config)
|
void RenderDeferredTask::configure(const Config& config)
|
||||||
{
|
{
|
||||||
DependencyManager::get<FadeEffect>()->setDebugEnabled(config.debugFade);
|
const float SCALE_MIN = 0.01f;
|
||||||
DependencyManager::get<FadeEffect>()->setDebugFadePercent(config.debugFadePercent);
|
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) {
|
void RenderDeferredTask::build(JobModel& task, const render::Varying& input, render::Varying& output) {
|
||||||
|
|
|
@ -164,9 +164,13 @@ public:
|
||||||
|
|
||||||
class RenderDeferredTaskConfig : public render::Task::Config {
|
class RenderDeferredTaskConfig : public render::Task::Config {
|
||||||
Q_OBJECT
|
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(bool debugFade MEMBER debugFade NOTIFY dirty)
|
||||||
Q_PROPERTY(float debugFadePercent MEMBER debugFadePercent NOTIFY dirty)
|
Q_PROPERTY(float debugFadePercent MEMBER debugFadePercent NOTIFY dirty)
|
||||||
public:
|
public:
|
||||||
|
float fadeScale{ 0.5f };
|
||||||
|
float fadeDuration{ 3.0f };
|
||||||
float debugFadePercent{ 0.f };
|
float debugFadePercent{ 0.f };
|
||||||
bool debugFade{ false };
|
bool debugFade{ false };
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ Row {
|
||||||
spacing: 8
|
spacing: 8
|
||||||
|
|
||||||
CheckBox {
|
CheckBox {
|
||||||
text: "Force Fade"
|
text: "Manual Fade"
|
||||||
checked: taskConfig["debugFade"]
|
checked: taskConfig["debugFade"]
|
||||||
onCheckedChanged: { taskConfig["debugFade"] = checked }
|
onCheckedChanged: { taskConfig["debugFade"] = checked }
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,24 @@ Row {
|
||||||
min: 0.0
|
min: 0.0
|
||||||
width: 250
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue