Skip to content

Commit f897c63

Browse files
committed
tweak(drawable): Decouple material opacity of detected stealth models from render update
Scalar value is calculated ahead of rendering.
1 parent e6c28a4 commit f897c63

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,9 @@ class Drawable : public Thing,
545545
inline Real getSecondMaterialPassOpacity() const { return m_secondMaterialPassOpacity; } ///< get alpha/opacity value used to render add'l rendering pass.
546546
void setSecondMaterialPassOpacity( Real op ) { m_secondMaterialPassOpacity = op; }; ///< set alpha/opacity value used to render add'l rendering pass.
547547

548+
Real getSecondMaterialPassOpacityScalar() const { return m_secondMaterialPassOpacityScalar; } ///< get alpha/opacity scalar value used to render e.g. detected stealth units.
549+
void setSecondMaterialPassOpacityScalar(Real scalar) { m_secondMaterialPassOpacityScalar = scalar; } ///< set alpha/opacity scalar value used to render e.g. detected stealth units.
550+
548551
// both of these assume that you are starting at one extreme 100% or 0% opacity and are trying to go to the other!! -- amit
549552
void fadeOut( UnsignedInt frames ); ///< fade object out...how gradually this is done is determined by frames
550553
void fadeIn( UnsignedInt frames ); ///< fade object in...how gradually this is done is determined by frames
@@ -724,6 +727,7 @@ class Drawable : public Thing,
724727
DrawableIconInfo* m_iconInfo; ///< lazily allocated!
725728

726729
Real m_secondMaterialPassOpacity; ///< drawable gets rendered again in hardware with an extra material layer
730+
Real m_secondMaterialPassOpacityScalar; ///< multiply opacity by scalar value; used for non-default render framerates
727731
// --------- BYTE-SIZED THINGS GO HERE
728732
Byte m_selected; ///< drawable is selected or not
729733
Bool m_hidden; ///< drawable is "hidden" or not (overrides stealth effects)

GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ Drawable::Drawable( const ThingTemplate *thingTemplate, DrawableStatusBits statu
433433
m_hidden = false;
434434
m_hiddenByStealth = false;
435435
m_secondMaterialPassOpacity = 0.0f;
436+
m_secondMaterialPassOpacityScalar = MATERIAL_PASS_OPACITY_FADE_SCALAR;
436437
m_drawableFullyObscuredByShroud = false;
437438

438439
m_receivesDynamicLights = TRUE; // a good default... overridden by one of my draw modules if at all
@@ -2612,7 +2613,8 @@ void Drawable::draw()
26122613
if ( getObject() && getObject()->isEffectivelyDead() )
26132614
m_secondMaterialPassOpacity = 0.0f;//dead folks don't stealth anyway
26142615
else if ( m_secondMaterialPassOpacity > VERY_TRANSPARENT_MATERIAL_PASS_OPACITY )// keep fading any add'l material unless something has set it to zero
2615-
m_secondMaterialPassOpacity *= MATERIAL_PASS_OPACITY_FADE_SCALAR;
2616+
// TheSuperHackers @tweak The opacity step is now decoupled from the render update.
2617+
m_secondMaterialPassOpacity *= m_secondMaterialPassOpacityScalar;
26162618
else
26172619
m_secondMaterialPassOpacity = 0.0f;
26182620
}

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthDetectorUpdate.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "Common/BitFlagsIO.h"
5252
#include "Common/PlayerList.h"
5353
#include "Common/Player.h"
54+
#include "Common/FramePacer.h"
5455

5556

5657
//-------------------------------------------------------------------------------------------------
@@ -304,9 +305,21 @@ UpdateSleepTime StealthDetectorUpdate::update( void )
304305
/** @todo srj -- evil hack here... this whole heat-vision thing is fucked.
305306
don't want it on mines but no good way to do that. hack for now. */
306307
Drawable *theirDraw = them->getDrawable();
307-
if ( theirDraw && !them->isKindOf(KINDOF_MINE))
308+
if (theirDraw && !them->isKindOf(KINDOF_MINE))
308309
{
309-
theirDraw->setSecondMaterialPassOpacity( 1.0f );
310+
constexpr const Real minOpacity = 0.05f;
311+
constexpr const Real resetThreshold = 2 * minOpacity;
312+
constexpr const Real updatesPerSec = 2.0f; // (LOGICFRAMES_PER_MSEC_REAL / data->m_updateRate (15))
313+
314+
// TheSuperHackers @tweak Reset opacity only below threshold to prevent models flickering from multiple detections or special powers.
315+
if (theirDraw->getSecondMaterialPassOpacity() < resetThreshold)
316+
{
317+
// calculate opacity scalar to get smooth pulsating effect decoupled from the render update
318+
// minOpacity = (X ^ (framerate / updatesPerSec)) -> e.g. [ 0.05 = X ^ (100 / 2) ] -> [ X = 0.941845 ] -> [ 0.941845 ^ 50 = 0.05 ]
319+
const Real scalar = pow(minOpacity, updatesPerSec / TheFramePacer->getUpdateFps());
320+
theirDraw->setSecondMaterialPassOpacityScalar(scalar);
321+
theirDraw->setSecondMaterialPassOpacity(1.0f);
322+
}
310323
}
311324

312325
if (data->m_IRGridParticleSysTmpl)

0 commit comments

Comments
 (0)