working on making other entities transparent

This commit is contained in:
SamGondelman 2016-08-02 18:09:42 -07:00
parent 5de21982be
commit d63a0ef08f
8 changed files with 36 additions and 19 deletions

View file

@ -1,4 +1,4 @@
//
//
// RenderableEntityItem.cpp
// interface/src
//
@ -19,7 +19,7 @@ namespace render {
if (payload->entity->getType() == EntityTypes::Light) {
return ItemKey::Builder::light();
}
if (payload && payload->entity->getType() == EntityTypes::PolyLine) {
if (payload && (payload->entity->getType() == EntityTypes::PolyLine || payload->entity->isTransparent())) {
return ItemKey::Builder::transparentShape();
}
}

View file

@ -40,7 +40,6 @@ static std::array<GeometryCache::Shape, entity::NUM_SHAPES> MAPPING { {
GeometryCache::Cylinder,
} };
RenderableShapeEntityItem::Pointer RenderableShapeEntityItem::baseFactory(const EntityItemID& entityID, const EntityItemProperties& properties) {
Pointer entity = std::make_shared<RenderableShapeEntityItem>(entityID);
entity->setProperties(properties);
@ -106,7 +105,13 @@ void RenderableShapeEntityItem::render(RenderArgs* args) {
DependencyManager::get<GeometryCache>()->renderShape(batch, MAPPING[_shape]);
} else {
// FIXME, support instanced multi-shape rendering using multidraw indirect
DependencyManager::get<GeometryCache>()->renderSolidShapeInstance(batch, MAPPING[_shape], color);
float fadeRatio = Interpolate::calculateFadeRatio(_fadeStartTime);
if (fadeRatio < 1.0f) {
color = glm::vec4(0.0f, 0.0f, 1.0f, 0.5f);
DependencyManager::get<GeometryCache>()->renderSolidShapeInstance(batch, MAPPING[_shape], color);
} else {
DependencyManager::get<GeometryCache>()->renderSolidShapeInstance(batch, MAPPING[_shape], color);
}
}

View file

@ -11,6 +11,7 @@
#include <ShapeEntityItem.h>
#include <procedural/Procedural.h>
#include <Interpolate.h>
#include "RenderableEntityItem.h"
@ -21,15 +22,18 @@ 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) {}
RenderableShapeEntityItem(const EntityItemID& entityItemID) : ShapeEntityItem(entityItemID), _fadeStartTime(usecTimestampNow()) {}
void render(RenderArgs* args) override;
void setUserData(const QString& value) override;
bool isTransparent() override { return Interpolate::calculateFadeRatio(_fadeStartTime) < 1.0f; }
SIMPLE_RENDERABLE();
private:
QSharedPointer<Procedural> _procedural;
quint64 _fadeStartTime { 0 };
};

View file

@ -435,6 +435,7 @@ public:
QUuid getOwningAvatarID() const { return _owningAvatarID; }
void setOwningAvatarID(const QUuid& owningAvatarID) { _owningAvatarID = owningAvatarID; }
virtual bool isTransparent() { return false; }
protected:

View file

@ -13,6 +13,8 @@
#include <PerfStat.h>
#include <Interpolate.h>
#include "DeferredLightingEffect.h"
#include "Model.h"
@ -352,16 +354,6 @@ void ModelMeshPartPayload::initCache() {
}
float ModelMeshPartPayload::calculateFadeRatio() const {
const float FADE_TIME = 1.0f;
float t = 2.0f * std::min(((float)(usecTimestampNow() - _fadeStartTime)) / ((float)(FADE_TIME * USECS_PER_SECOND)), 1.0f);
float fadeRatio = (t < 1.0f) ? 0.5f * powf(2.0f, 10.0f * (t - 1.0f)) : 0.5f * (-powf(2.0f, -10.0f * (t - 1.0f)) + 2.0f);
// The easing function isn't exactly 1 at t = 2, so we need to scale the whole function up slightly
const float EASING_SCALE = 1.001f;
return std::min(EASING_SCALE * fadeRatio, 1.0f);
}
void ModelMeshPartPayload::notifyLocationChanged() {
}
@ -401,7 +393,7 @@ ItemKey ModelMeshPartPayload::getKey() const {
}
}
if (calculateFadeRatio() < 1.0f) {
if (Interpolate::calculateFadeRatio(_fadeStartTime) < 1.0f) {
builder.withTransparent();
}
@ -456,7 +448,7 @@ ShapeKey ModelMeshPartPayload::getShapeKey() const {
}
ShapeKey::Builder builder;
if (isTranslucent || calculateFadeRatio() < 1.0f) {
if (isTranslucent || Interpolate::calculateFadeRatio(_fadeStartTime) < 1.0f) {
builder.withTranslucent();
}
if (hasTangents) {
@ -497,7 +489,7 @@ void ModelMeshPartPayload::bindMesh(gpu::Batch& batch) const {
batch.setInputStream(2, _drawMesh->getVertexStream().makeRangedStream(2));
}
float fadeRatio = calculateFadeRatio();
float fadeRatio = Interpolate::calculateFadeRatio(_fadeStartTime);
if (!_hasColorAttrib || fadeRatio < 1.0f) {
batch._glColor4f(1.0f, 1.0f, 1.0f, fadeRatio);
}

View file

@ -82,7 +82,6 @@ public:
void updateTransformForSkinnedMesh(const Transform& transform, const Transform& offsetTransform, const QVector<glm::mat4>& clusterMatrices);
// Entity fade in
float calculateFadeRatio() const;
void startFade() { _fadeStartTime = usecTimestampNow(); }
bool hasStartedFade() { return _hasStartedFade; }
void setHasStartedFade(bool hasStartedFade) { _hasStartedFade = hasStartedFade; }

View file

@ -14,6 +14,8 @@
#include <assert.h>
#include <math.h>
#include "NumericalConstants.h"
float Interpolate::bezierInterpolate(float y1, float y2, float y3, float u) {
// https://en.wikipedia.org/wiki/Bezier_curve
assert(0.0f <= u && u <= 1.0f);
@ -58,3 +60,13 @@ float Interpolate::interpolate3Points(float y1, float y2, float y3, float u) {
}
}
}
float Interpolate::calculateFadeRatio(quint64 start) {
const float FADE_TIME = 1.0f;
float t = 2.0f * std::min(((float)(usecTimestampNow() - start)) / ((float)(FADE_TIME * USECS_PER_SECOND)), 1.0f);
float fadeRatio = (t < 1.0f) ? 0.5f * powf(2.0f, 10.0f * (t - 1.0f)) : 0.5f * (-powf(2.0f, -10.0f * (t - 1.0f)) + 2.0f);
// The easing function isn't exactly 1 at t = 2, so we need to scale the whole function up slightly
const float EASING_SCALE = 1.001f;
return std::min(EASING_SCALE * fadeRatio, 1.0f);
}

View file

@ -12,6 +12,8 @@
#ifndef hifi_Interpolate_h
#define hifi_Interpolate_h
#include "SharedUtil.h"
class Interpolate {
public:
@ -22,6 +24,8 @@ public:
// Interpolate at position u [0.0 - 1.0] between y values equally spaced along the x-axis such that the interpolated values
// pass through all three y values. Return value lies wholly within the range of y values passed in.
static float interpolate3Points(float y1, float y2, float y3, float u);
static float calculateFadeRatio(quint64 start);
};
#endif // hifi_Interpolate_h