Added debug scripts and fade position is now stable

This commit is contained in:
Olivier Prat 2017-04-30 14:42:27 +02:00
parent 14b2b98db6
commit 111f0762ea
12 changed files with 114 additions and 41 deletions

View file

@ -9,11 +9,18 @@
<@if not FADE_SLH@> <@if not FADE_SLH@>
<@def FADE_SLH@> <@def FADE_SLH@>
<@func declareFade()@> <@func transformModelToFadePos(objectTransform, objectPosition, fadePosition)@>
{
<$transformModelToWorldPos($objectTransform$, $objectPosition$, $fadePosition$)$>
<$fadePosition$> -= vec4(<$objectTransform$>._model[3].xyz, 0.f);
}
<@endfunc@>
<@func declareFadeFragment()@>
struct Fade { struct Fade {
vec3 _Offset; vec3 _Offset;
float _Percent; float _Percent;
}; };
uniform fadeBuffer { uniform fadeBuffer {
@ -30,8 +37,8 @@ float evalFadeMask(vec3 position, vec3 normal) {
const float FADE_MASK_INV_SCALE = 1.0; const float FADE_MASK_INV_SCALE = 1.0;
// Do tri-linear interpolation // Do tri-linear interpolation
vec3 noisePosition = position * FADE_MASK_INV_SCALE; vec3 noisePosition = position * FADE_MASK_INV_SCALE + fade._Offset;
vec3 noisePositionFloored = floor(noisePosition) + fade._Offset; vec3 noisePositionFloored = floor(noisePosition);
vec3 noisePositionFraction = fract(noisePosition); vec3 noisePositionFraction = fract(noisePosition);
float noiseLowXLowYLowZ = textureLod(fadeMaskMap, hash2D(noisePositionFloored), 0).r; float noiseLowXLowYLowZ = textureLod(fadeMaskMap, hash2D(noisePositionFloored), 0).r;
float noiseLowXHighYLowZ = textureLod(fadeMaskMap, hash2D(noisePositionFloored+vec3(0,1,0)), 0).r; float noiseLowXHighYLowZ = textureLod(fadeMaskMap, hash2D(noisePositionFloored+vec3(0,1,0)), 0).r;

View file

@ -523,37 +523,40 @@ void ModelMeshPartPayload::bindTransform(gpu::Batch& batch, const ShapePipeline:
batch.setModelTransform(_transform); batch.setModelTransform(_transform);
} }
float ModelMeshPartPayload::computeFadePercent(bool isDebugEnabled) const { float ModelMeshPartPayload::computeFadePercent() const {
if (!isDebugEnabled) { if (_fadeState == FADE_WAITING_TO_START) {
if (_fadeState == FADE_WAITING_TO_START) { return 0.0f;
return 0.0f;
}
float fadeAlpha = 1.0f;
const float INV_FADE_PERIOD = 1.0f / (float)(3 * USECS_PER_SECOND);
float fraction = (float)(usecTimestampNow() - _fadeStartTime) * INV_FADE_PERIOD;
if (fraction < 1.0f) {
fadeAlpha = Interpolate::simpleNonLinearBlend(fraction);
}
if (fadeAlpha >= 1.0f) {
_fadeState = FADE_COMPLETE;
// when fade-in completes we flag model for one last "render item update"
_model->setRenderItemsNeedUpdate();
return 1.0f;
}
return Interpolate::simpleNonLinearBlend(fadeAlpha);
} }
else { float fadeAlpha = 1.0f;
// Animate fade for debugging purposes during repeated 3 second cycles const float INV_FADE_PERIOD = 1.0f / (float)(3 * USECS_PER_SECOND);
return (usecTimestampNow() % (3 * USECS_PER_SECOND)) / (float)(3 * USECS_PER_SECOND); float fraction = (float)(usecTimestampNow() - _fadeStartTime) * INV_FADE_PERIOD;
if (fraction < 1.0f) {
fadeAlpha = Interpolate::simpleNonLinearBlend(fraction);
} }
if (fadeAlpha >= 1.0f) {
_fadeState = FADE_COMPLETE;
// when fade-in completes we flag model for one last "render item update"
_model->setRenderItemsNeedUpdate();
return 1.0f;
}
return Interpolate::simpleNonLinearBlend(fadeAlpha);
} }
void ModelMeshPartPayload::bindFade(gpu::Batch& batch, bool isDebugEnabled) const { void ModelMeshPartPayload::bindFade(gpu::Batch& batch, const RenderArgs* args) const {
const bool isDebugEnabled = (args->_debugFlags & RenderArgs::RENDER_DEBUG_FADE) != 0;
if (_fadeState != FADE_COMPLETE || isDebugEnabled) { if (_fadeState != FADE_COMPLETE || isDebugEnabled) {
auto& fade = _fadeBuffer.edit<Fade>(); auto& fade = _fadeBuffer.edit<Fade>();
glm::vec3 offset = _transform.getTranslation(); glm::vec3 offset = _transform.getTranslation();
fade._percent = computeFadePercent(isDebugEnabled); // A bit ugly to have the test at every bind...
if (!isDebugEnabled) {
fade._percent = computeFadePercent();
}
else {
fade._percent = args->_debugFadePercent;
}
fade._offset = offset; fade._offset = offset;
batch.setUniformBuffer(ShapePipeline::Slot::BUFFER::FADE, _fadeBuffer); batch.setUniformBuffer(ShapePipeline::Slot::BUFFER::FADE, _fadeBuffer);
} }
@ -605,7 +608,7 @@ void ModelMeshPartPayload::render(RenderArgs* args) {
bindMaterial(batch, locations, args->_enableTexturing); bindMaterial(batch, locations, args->_enableTexturing);
// Apply fade effect // Apply fade effect
bindFade(batch, (args->_debugFlags & RenderArgs::RENDER_DEBUG_FADE) != 0); bindFade(batch, args);
args->_details._materialSwitches++; args->_details._materialSwitches++;

View file

@ -93,7 +93,7 @@ public:
const Transform& boundTransform, const Transform& boundTransform,
const gpu::BufferPointer& buffer); const gpu::BufferPointer& buffer);
float computeFadePercent(bool isDebugEnabled) const; float computeFadePercent() const;
// Render Item interface // Render Item interface
render::ItemKey getKey() const override; render::ItemKey getKey() const override;
@ -104,7 +104,7 @@ public:
// ModelMeshPartPayload functions to perform render // ModelMeshPartPayload functions to perform render
void bindMesh(gpu::Batch& batch) override; void bindMesh(gpu::Batch& batch) override;
void bindTransform(gpu::Batch& batch, const render::ShapePipeline::LocationsPointer locations, RenderArgs::RenderMode renderMode) const override; void bindTransform(gpu::Batch& batch, const render::ShapePipeline::LocationsPointer locations, RenderArgs::RenderMode renderMode) const override;
void bindFade(gpu::Batch& batch, bool isDebugEnabled) const; void bindFade(gpu::Batch& batch, const RenderArgs* args) const;
void initCache(); void initCache();

View file

@ -325,6 +325,7 @@ void DrawStateSortDeferred::run(const RenderContextPointer& renderContext, const
if (_debugFade) { if (_debugFade) {
args->_debugFlags = static_cast<RenderArgs::DebugFlags>(args->_debugFlags | args->_debugFlags = static_cast<RenderArgs::DebugFlags>(args->_debugFlags |
static_cast<int>(RenderArgs::RENDER_DEBUG_FADE)); static_cast<int>(RenderArgs::RENDER_DEBUG_FADE));
args->_debugFadePercent = _debugFadePercent;
// Force fade for everyone // Force fade for everyone
keyBuilder.withFade(); keyBuilder.withFade();
} }

View file

@ -87,12 +87,14 @@ class DrawStateSortConfig : public render::Job::Config {
Q_PROPERTY(int maxDrawn MEMBER maxDrawn NOTIFY dirty) Q_PROPERTY(int maxDrawn MEMBER maxDrawn NOTIFY dirty)
Q_PROPERTY(bool stateSort MEMBER stateSort NOTIFY dirty) Q_PROPERTY(bool stateSort MEMBER stateSort 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)
public: public:
int getNumDrawn() { return numDrawn; } int getNumDrawn() { return numDrawn; }
void setNumDrawn(int num) { numDrawn = num; emit numDrawnChanged(); } void setNumDrawn(int num) { numDrawn = num; emit numDrawnChanged(); }
int maxDrawn{ -1 }; int maxDrawn{ -1 };
float debugFadePercent{ 0.f };
bool stateSort{ true }; bool stateSort{ true };
bool debugFade{ false }; bool debugFade{ false };
@ -113,13 +115,14 @@ public:
DrawStateSortDeferred(render::ShapePlumberPointer shapePlumber, gpu::TexturePointer fadeMaskMap) : _shapePlumber{ shapePlumber }, _fadeMaskMap{ fadeMaskMap } {} DrawStateSortDeferred(render::ShapePlumberPointer shapePlumber, gpu::TexturePointer fadeMaskMap) : _shapePlumber{ shapePlumber }, _fadeMaskMap{ fadeMaskMap } {}
void configure(const Config& config) { _maxDrawn = config.maxDrawn; _stateSort = config.stateSort; _debugFade = config.debugFade; } void configure(const Config& config) { _maxDrawn = config.maxDrawn; _stateSort = config.stateSort; _debugFadePercent = config.debugFadePercent; _debugFade = config.debugFade; }
void run(const render::RenderContextPointer& renderContext, const Inputs& inputs); void run(const render::RenderContextPointer& renderContext, const Inputs& inputs);
protected: protected:
render::ShapePlumberPointer _shapePlumber; render::ShapePlumberPointer _shapePlumber;
gpu::TexturePointer _fadeMaskMap; gpu::TexturePointer _fadeMaskMap;
int _maxDrawn; // initialized by Config int _maxDrawn; // initialized by Config
float _debugFadePercent;
bool _stateSort; bool _stateSort;
bool _debugFade; bool _debugFade;
}; };

View file

@ -19,10 +19,10 @@
<$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, _SCRIBE_NULL, EMISSIVE, OCCLUSION)$> <$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, _SCRIBE_NULL, EMISSIVE, OCCLUSION)$>
<@include Fade.slh@> <@include Fade.slh@>
<$declareFade()$> <$declareFadeFragment()$>
in vec4 _position; in vec4 _position;
in vec4 _worldPosition; in vec4 _worldFadePosition;
in vec3 _normal; in vec3 _normal;
in vec3 _color; in vec3 _color;
in vec2 _texCoord0; in vec2 _texCoord0;
@ -30,7 +30,7 @@ in vec2 _texCoord1;
void main(void) { void main(void) {
applyFade(_worldPosition.xyz, _normal); applyFade(_worldFadePosition.xyz, _normal);
Material mat = getMaterial(); Material mat = getMaterial();
int matKey = getMaterialKey(mat); int matKey = getMaterialKey(mat);

View file

@ -19,12 +19,14 @@
<@include MaterialTextures.slh@> <@include MaterialTextures.slh@>
<$declareMaterialTexMapArrayBuffer()$> <$declareMaterialTexMapArrayBuffer()$>
<@include Fade.slh@>
out vec3 _color; out vec3 _color;
out float _alpha; out float _alpha;
out vec2 _texCoord0; out vec2 _texCoord0;
out vec2 _texCoord1; out vec2 _texCoord1;
out vec4 _position; out vec4 _position;
out vec4 _worldPosition; out vec4 _worldFadePosition;
out vec3 _normal; out vec3 _normal;
void main(void) { void main(void) {
@ -39,6 +41,6 @@ void main(void) {
TransformCamera cam = getTransformCamera(); TransformCamera cam = getTransformCamera();
TransformObject obj = getTransformObject(); TransformObject obj = getTransformObject();
<$transformModelToEyeAndClipPos(cam, obj, inPosition, _position, gl_Position)$> <$transformModelToEyeAndClipPos(cam, obj, inPosition, _position, gl_Position)$>
<$transformModelToWorldPos(obj, inPosition, _worldPosition)$> <$transformModelToFadePos(obj, inPosition, _worldFadePosition)$>
<$transformModelToWorldDir(cam, obj, inNormal.xyz, _normal)$> <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normal)$>
} }

View file

@ -20,10 +20,10 @@
<$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, _SCRIBE_NULL, EMISSIVE, OCCLUSION, SCATTERING)$> <$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, _SCRIBE_NULL, EMISSIVE, OCCLUSION, SCATTERING)$>
<@include Fade.slh@> <@include Fade.slh@>
<$declareFade()$> <$declareFadeFragment()$>
in vec4 _position; in vec4 _position;
in vec4 _worldPosition; in vec4 _worldFadePosition;
in vec2 _texCoord0; in vec2 _texCoord0;
in vec2 _texCoord1; in vec2 _texCoord1;
in vec3 _normal; in vec3 _normal;
@ -31,7 +31,7 @@ in vec3 _tangent;
in vec3 _color; in vec3 _color;
void main(void) { void main(void) {
applyFade(_worldPosition.xyz, _normal); applyFade(_worldFadePosition.xyz, _normal);
Material mat = getMaterial(); Material mat = getMaterial();
int matKey = getMaterialKey(mat); int matKey = getMaterialKey(mat);

View file

@ -20,8 +20,10 @@
<@include MaterialTextures.slh@> <@include MaterialTextures.slh@>
<$declareMaterialTexMapArrayBuffer()$> <$declareMaterialTexMapArrayBuffer()$>
<@include Fade.slh@>
out vec4 _position; out vec4 _position;
out vec4 _worldPosition; out vec4 _worldFadePosition;
out vec2 _texCoord0; out vec2 _texCoord0;
out vec2 _texCoord1; out vec2 _texCoord1;
out vec3 _normal; out vec3 _normal;
@ -42,7 +44,7 @@ void main(void) {
TransformCamera cam = getTransformCamera(); TransformCamera cam = getTransformCamera();
TransformObject obj = getTransformObject(); TransformObject obj = getTransformObject();
<$transformModelToEyeAndClipPos(cam, obj, inPosition, _position, gl_Position)$> <$transformModelToEyeAndClipPos(cam, obj, inPosition, _position, gl_Position)$>
<$transformModelToWorldPos(obj, inPosition, _worldPosition)$> <$transformModelToFadePos(obj, inPosition, _worldFadePosition)$>
<$transformModelToWorldDir(cam, obj, inNormal.xyz, _normal)$> <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normal)$>
<$transformModelToWorldDir(cam, obj, inTangent.xyz, _tangent)$> <$transformModelToWorldDir(cam, obj, inTangent.xyz, _tangent)$>
} }

View file

@ -133,6 +133,7 @@ public:
RenderDetails _details; RenderDetails _details;
render::ScenePointer _scene; // HACK render::ScenePointer _scene; // HACK
int8_t _cameraMode { -1 }; // HACK int8_t _cameraMode { -1 }; // HACK
float _debugFadePercent{ 0.f }; // HACK too
}; };
#endif // hifi_RenderArgs_h #endif // hifi_RenderArgs_h

View file

@ -0,0 +1,21 @@
//
// debugFade.js
// developer/utilities/render
//
// Olivier Prat, created on 30/04/2017.
// Copyright 2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// Set up the qml ui
var qml = Script.resolvePath('fade.qml');
var window = new OverlayWindow({
title: 'Fade',
source: qml,
width: 400,
height: 80
});
window.setPosition(50, 50);
window.closed.connect(function() { Script.stop(); });

View file

@ -0,0 +1,33 @@
//
// fade.qml
// developer/utilities/render
//
// Olivier Prat, created on 30/04/2017.
// Copyright 2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html
//
import QtQuick 2.5
import QtQuick.Controls 1.4
import "configSlider"
Column {
id: root
spacing: 8
property var drawOpaqueConfig: Render.getConfig("DrawOpaqueDeferred");
CheckBox {
text: "Force Fade"
checked: drawOpaqueConfig["debugFade"]
onCheckedChanged: { drawOpaqueConfig["debugFade"] = checked }
}
ConfigSlider {
label: "Percent"
integral: false
config: drawOpaqueConfig
property: "debugFadePercent"
max: 1.0
min: 0.0
}
}