mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 11:35:20 +02:00
fade on texture load
This commit is contained in:
parent
217a102926
commit
313ba87fce
3 changed files with 14 additions and 12 deletions
|
@ -329,8 +329,6 @@ ModelMeshPartPayload::ModelMeshPartPayload(Model* model, int _meshIndex, int par
|
||||||
|
|
||||||
updateTransform(transform, offsetTransform);
|
updateTransform(transform, offsetTransform);
|
||||||
initCache();
|
initCache();
|
||||||
|
|
||||||
_fadeStartTime = usecTimestampNow();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelMeshPartPayload::initCache() {
|
void ModelMeshPartPayload::initCache() {
|
||||||
|
@ -357,7 +355,7 @@ void ModelMeshPartPayload::initCache() {
|
||||||
float ModelMeshPartPayload::calcFadeRatio() const {
|
float ModelMeshPartPayload::calcFadeRatio() const {
|
||||||
const float FADE_TIME = 0.5f;
|
const float FADE_TIME = 0.5f;
|
||||||
float t = std::min(((float)(usecTimestampNow() - _fadeStartTime)) / ((float)(FADE_TIME * USECS_PER_SECOND)), 1.0f);
|
float t = std::min(((float)(usecTimestampNow() - _fadeStartTime)) / ((float)(FADE_TIME * USECS_PER_SECOND)), 1.0f);
|
||||||
return -0.5f * (cosf(M_PI*t) - 1.0f);
|
return -(cosf(M_PI_2*t) - 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelMeshPartPayload::notifyLocationChanged() {
|
void ModelMeshPartPayload::notifyLocationChanged() {
|
||||||
|
@ -495,9 +493,9 @@ void ModelMeshPartPayload::bindMesh(gpu::Batch& batch) const {
|
||||||
batch.setInputStream(2, _drawMesh->getVertexStream().makeRangedStream(2));
|
batch.setInputStream(2, _drawMesh->getVertexStream().makeRangedStream(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Get rid of that extra call
|
float fadeRatio = calcFadeRatio();
|
||||||
if (!_hasColorAttrib) {
|
if (!_hasColorAttrib || fadeRatio < 1.0f) {
|
||||||
batch._glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
batch._glColor4f(1.0f, 1.0f, 1.0f, fadeRatio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -528,7 +526,7 @@ void ModelMeshPartPayload::bindTransform(gpu::Batch& batch, const ShapePipeline:
|
||||||
void ModelMeshPartPayload::render(RenderArgs* args) const {
|
void ModelMeshPartPayload::render(RenderArgs* args) const {
|
||||||
PerformanceTimer perfTimer("ModelMeshPartPayload::render");
|
PerformanceTimer perfTimer("ModelMeshPartPayload::render");
|
||||||
|
|
||||||
if (!_model->_readyWhenAdded || !_model->_isVisible) {
|
if (!_model->_readyWhenAdded || !_model->_isVisible || !_hasStartedFade) {
|
||||||
return; // bail asap
|
return; // bail asap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -552,9 +550,6 @@ void ModelMeshPartPayload::render(RenderArgs* args) const {
|
||||||
// apply material properties
|
// apply material properties
|
||||||
bindMaterial(batch, locations);
|
bindMaterial(batch, locations);
|
||||||
|
|
||||||
// model fading
|
|
||||||
batch._glColor4f(1.0f, 1.0f, 1.0f, calcFadeRatio());
|
|
||||||
|
|
||||||
if (args) {
|
if (args) {
|
||||||
args->_details._materialSwitches++;
|
args->_details._materialSwitches++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,6 +83,9 @@ public:
|
||||||
|
|
||||||
// Entity fade in
|
// Entity fade in
|
||||||
float calcFadeRatio() const;
|
float calcFadeRatio() const;
|
||||||
|
void startFade() { _fadeStartTime = usecTimestampNow(); }
|
||||||
|
bool hasStartedFade() { return _hasStartedFade; }
|
||||||
|
void setHasStartedFade(bool hasStartedFade) { _hasStartedFade = hasStartedFade; }
|
||||||
|
|
||||||
// Render Item interface
|
// Render Item interface
|
||||||
render::ItemKey getKey() const override;
|
render::ItemKey getKey() const override;
|
||||||
|
@ -104,8 +107,8 @@ public:
|
||||||
bool _isBlendShaped{ false };
|
bool _isBlendShaped{ false };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
quint64 _fadeStartTime { usecTimestampNow() };
|
quint64 _fadeStartTime { 0 };
|
||||||
bool _hasFadeStarted { false };
|
bool _hasStartedFade { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace render {
|
namespace render {
|
||||||
|
|
|
@ -207,6 +207,10 @@ void Model::updateRenderItems() {
|
||||||
render::PendingChanges pendingChanges;
|
render::PendingChanges pendingChanges;
|
||||||
foreach (auto itemID, self->_modelMeshRenderItems.keys()) {
|
foreach (auto itemID, self->_modelMeshRenderItems.keys()) {
|
||||||
pendingChanges.updateItem<ModelMeshPartPayload>(itemID, [modelTransform, modelMeshOffset, deleteGeometryCounter](ModelMeshPartPayload& data) {
|
pendingChanges.updateItem<ModelMeshPartPayload>(itemID, [modelTransform, modelMeshOffset, deleteGeometryCounter](ModelMeshPartPayload& data) {
|
||||||
|
if (!data.hasStartedFade() && data._model && data._model->isLoaded() && data._model->getGeometry()->areTexturesLoaded()) {
|
||||||
|
data.startFade();
|
||||||
|
data.setHasStartedFade(true);
|
||||||
|
}
|
||||||
// Ensure the model geometry was not reset between frames
|
// Ensure the model geometry was not reset between frames
|
||||||
if (data._model && data._model->isLoaded() && deleteGeometryCounter == data._model->_deleteGeometryCounter) {
|
if (data._model && data._model->isLoaded() && deleteGeometryCounter == data._model->_deleteGeometryCounter) {
|
||||||
// lazy update of cluster matrices used for rendering. We need to update them here, so we can correctly update the bounding box.
|
// lazy update of cluster matrices used for rendering. We need to update them here, so we can correctly update the bounding box.
|
||||||
|
|
Loading…
Reference in a new issue