fixed procedural entity fade

This commit is contained in:
SamGondelman 2016-08-05 16:15:10 -07:00
parent 8494400047
commit b794259b7d
5 changed files with 17 additions and 11 deletions
libraries
entities-renderer/src
procedural/src/procedural
render-utils/src

View file

@ -71,13 +71,13 @@ void RenderableShapeEntityItem::setUserData(const QString& value) {
}
}
/*bool RenderableShapeEntityItem::isTransparent() {
bool RenderableShapeEntityItem::isTransparent() {
if (_procedural && _procedural->ready()) {
return Interpolate::calculateFadeRatio(_procedural->getFadeStartTime()) < 1.0f;
} else {
return EntityItem::isTransparent();
}
}*/
}
void RenderableShapeEntityItem::render(RenderArgs* args) {
PerformanceTimer perfTimer("RenderableShapeEntityItem::render");
@ -91,7 +91,7 @@ void RenderableShapeEntityItem::render(RenderArgs* args) {
_procedural->_fragmentSource = simple_frag;
_procedural->_state->setCullMode(gpu::State::CULL_NONE);
_procedural->_state->setDepthTest(true, true, gpu::LESS_EQUAL);
_procedural->_state->setBlendFunction(false,
_procedural->_state->setBlendFunction(true,
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
}

View file

@ -21,17 +21,17 @@ public:
static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties);
static EntityItemPointer boxFactory(const EntityItemID& entityID, const EntityItemProperties& properties);
static EntityItemPointer sphereFactory(const EntityItemID& entityID, const EntityItemProperties& properties);
RenderableShapeEntityItem(const EntityItemID& entityItemID) : ShapeEntityItem(entityItemID) { _procedural.reset(nullptr); }
RenderableShapeEntityItem(const EntityItemID& entityItemID) : ShapeEntityItem(entityItemID) {}
void render(RenderArgs* args) override;
void setUserData(const QString& value) override;
// bool isTransparent() override;
SIMPLE_RENDERABLE();
bool isTransparent() override;
private:
QSharedPointer<Procedural> _procedural;
std::unique_ptr<Procedural> _procedural { nullptr };
SIMPLE_RENDERABLE();
};

View file

@ -175,6 +175,10 @@ void Procedural::parse(const QJsonObject& proceduralData) {
}
bool Procedural::ready() {
if (!_hasStartedFade) {
_fadeStartTime = usecTimestampNow();
}
// Load any changes to the procedural
// Check for changes atomically, in case they are currently being made
if (_proceduralDataDirty) {
@ -184,7 +188,6 @@ bool Procedural::ready() {
// Reset dirty flag after reading _proceduralData, but before releasing lock
// to avoid resetting it after more data is set
_proceduralDataDirty = false;
_fadeStartTime = usecTimestampNow();
}
if (!_enabled) {
@ -203,6 +206,9 @@ bool Procedural::ready() {
}
}
if (!_hasStartedFade) {
_hasStartedFade = true;
}
return true;
}

View file

@ -109,6 +109,7 @@ private:
void setupChannels(bool shouldCreate);
quint64 _fadeStartTime;
bool _hasStartedFade { false };
};
#endif

View file

@ -52,11 +52,10 @@ void main(void) {
const float ALPHA_THRESHOLD = 0.999;
if (_color.a < ALPHA_THRESHOLD) {
if (emissiveAmount > 0.0) {
// TODO: transparent emissive?
packDeferredFragmentTranslucent(
normal,
_color.a,
diffuse,
specular,
DEFAULT_FRESNEL,
DEFAULT_ROUGHNESS);
} else {