mirror of
https://github.com/lubosz/overte.git
synced 2025-04-10 04:52:17 +02:00
try to fade in procedural shapes
This commit is contained in:
parent
2eb0c7735f
commit
27bacc9165
6 changed files with 64 additions and 10 deletions
|
@ -71,6 +71,14 @@ void RenderableShapeEntityItem::setUserData(const QString& value) {
|
|||
}
|
||||
}
|
||||
|
||||
bool RenderableShapeEntityItem::isTransparent() {
|
||||
if (_procedural && _procedural->ready()) {
|
||||
return Interpolate::calculateFadeRatio(_procedural->getFadeStartTime()) < 1.0f;
|
||||
} else {
|
||||
return Interpolate::calculateFadeRatio(_fadeStartTime) < 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void RenderableShapeEntityItem::render(RenderArgs* args) {
|
||||
PerformanceTimer perfTimer("RenderableShapeEntityItem::render");
|
||||
//Q_ASSERT(getType() == EntityTypes::Shape);
|
||||
|
@ -101,6 +109,7 @@ void RenderableShapeEntityItem::render(RenderArgs* args) {
|
|||
if (_procedural->ready()) {
|
||||
_procedural->prepare(batch, getPosition(), getDimensions(), getOrientation());
|
||||
auto outColor = _procedural->getColor(color);
|
||||
outColor.a *= Interpolate::calculateFadeRatio(_procedural->getFadeStartTime());
|
||||
batch._glColor4f(outColor.r, outColor.g, outColor.b, outColor.a);
|
||||
DependencyManager::get<GeometryCache>()->renderShape(batch, MAPPING[_shape]);
|
||||
} else {
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
void render(RenderArgs* args) override;
|
||||
void setUserData(const QString& value) override;
|
||||
|
||||
bool isTransparent() override { return Interpolate::calculateFadeRatio(_fadeStartTime) < 1.0f; }
|
||||
bool isTransparent() override;
|
||||
|
||||
SIMPLE_RENDERABLE();
|
||||
|
||||
|
|
|
@ -184,6 +184,7 @@ 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) {
|
||||
|
|
|
@ -42,6 +42,7 @@ public:
|
|||
const gpu::ShaderPointer& getShader() const { return _shader; }
|
||||
|
||||
glm::vec4 getColor(const glm::vec4& entityColor);
|
||||
quint64 getFadeStartTime() { return _fadeStartTime; }
|
||||
|
||||
uint8_t _version { 1 };
|
||||
|
||||
|
@ -106,6 +107,8 @@ private:
|
|||
|
||||
void setupUniforms();
|
||||
void setupChannels(bool shouldCreate);
|
||||
|
||||
quint64 _fadeStartTime;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -49,11 +49,43 @@ void main(void) {
|
|||
|
||||
#endif
|
||||
|
||||
if (emissiveAmount > 0.0) {
|
||||
packDeferredFragmentLightmap(
|
||||
normal, 1.0, diffuse, max(0, 1.0 - shininess / 128.0), DEFAULT_METALLIC, specular, specular);
|
||||
if (_color.a < 1.0) {
|
||||
if (emissiveAmount > 0.0) {
|
||||
// TODO: transparent emissive?
|
||||
packDeferredFragmentTranslucent(
|
||||
normal,
|
||||
_color.a,
|
||||
diffuse,
|
||||
DEFAULT_FRESNEL,
|
||||
DEFAULT_ROUGHNESS);
|
||||
} else {
|
||||
packDeferredFragmentTranslucent(
|
||||
normal,
|
||||
_color.a,
|
||||
diffuse,
|
||||
DEFAULT_FRESNEL,
|
||||
DEFAULT_ROUGHNESS);
|
||||
}
|
||||
} else {
|
||||
packDeferredFragment(
|
||||
normal, 1.0, diffuse, max(0, 1.0 - shininess / 128.0), length(specular), DEFAULT_EMISSIVE, DEFAULT_OCCLUSION, DEFAULT_SCATTERING);
|
||||
if (emissiveAmount > 0.0) {
|
||||
packDeferredFragmentLightmap(
|
||||
normal,
|
||||
1.0,
|
||||
diffuse,
|
||||
max(0, 1.0 - shininess / 128.0),
|
||||
DEFAULT_METALLIC,
|
||||
specular,
|
||||
specular);
|
||||
} else {
|
||||
packDeferredFragment(
|
||||
normal,
|
||||
1.0,
|
||||
diffuse,
|
||||
max(0, 1.0 - shininess / 128.0),
|
||||
length(specular),
|
||||
DEFAULT_EMISSIVE,
|
||||
DEFAULT_OCCLUSION,
|
||||
DEFAULT_SCATTERING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,8 +29,17 @@ void main(void) {
|
|||
texel = colorToLinearRGBA(texel);
|
||||
}
|
||||
|
||||
packDeferredFragmentUnlit(
|
||||
normalize(_normal),
|
||||
texel.a,
|
||||
_color.rgb * texel.rgb);
|
||||
if (_color.a * texel.a < 1.0) {
|
||||
packDeferredFragmentTranslucent(
|
||||
normalize(_normal),
|
||||
_color.a * texel.a,
|
||||
_color.rgb * texel.rgb,
|
||||
DEFAULT_FRESNEL,
|
||||
DEFAULT_ROUGHNESS);
|
||||
} else {
|
||||
packDeferredFragmentUnlit(
|
||||
normalize(_normal),
|
||||
1.0,
|
||||
_color.rgb * texel.rgb);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue