Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions trinity/Eve/SpaceObject/Children/EveChildPostProcessVolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
EveChildPostProcessVolume::EveChildPostProcessVolume( IRoot* lockobj ) :
PARENTLOCK( m_volumes ),
PARENTLOCK( m_exclusionVolumes ),
m_boundingSphere( Vector3( 0.0, 0.0, 0.0 ), 0.0 )
m_boundingSphere( Vector3( 0.0, 0.0, 0.0 ), 0.0 ),
m_enabled( true ),
m_intensityMultiplier( 1.f ),
m_minimumTransitionTime( 0.f )
{
m_postProcessAttributes.CreateInstance();
m_postProcessAttributes->intensity = 0.0f;
Expand Down Expand Up @@ -88,14 +91,12 @@ void EveChildPostProcessVolume::UpdateAsyncronous( const EveUpdateContext& updat

RebuildBoundingSphere();

float targetIntensity = m_enabled ? 1.0f : 0.0f;

// global postprocess volumes have no volumes, so they are always on
if( m_volumes.size() == 0 )
{
m_postProcessAttributes->intensity = 1.0f;
}
else
if( m_enabled && m_volumes.size() != 0 )
{
m_postProcessAttributes->intensity = 0.0f;
targetIntensity = 0.0f;

Matrix inverseWorldTransform = Inverse( m_worldTransform );
Vector3 cameraInObjectSpace = Transform( Tr2Renderer::GetViewPosition(), inverseWorldTransform ).GetXYZ();
Expand All @@ -106,15 +107,15 @@ void EveChildPostProcessVolume::UpdateAsyncronous( const EveUpdateContext& updat
// Now find the intensity within the volumes
for( const auto& volume : m_volumes )
{
m_postProcessAttributes->intensity = std::max( m_postProcessAttributes->intensity, volume->GetIntensity( cameraInObjectSpace ) );
if( m_postProcessAttributes->intensity == 1.0f )
targetIntensity = std::max( targetIntensity, volume->GetIntensity( cameraInObjectSpace ) );
if( targetIntensity == 1.0f )
{
// early exit
break;
}
}

if( m_postProcessAttributes->intensity != 0.0f )
if( targetIntensity != 0.0f )
{
// check if the camera is within an exclusion volume
float negativeIntensity = 0.0f;
Expand All @@ -127,10 +128,25 @@ void EveChildPostProcessVolume::UpdateAsyncronous( const EveUpdateContext& updat
break;
}
}
m_postProcessAttributes->intensity = std::max( 0.0f, m_postProcessAttributes->intensity - negativeIntensity );
targetIntensity = std::max( 0.0f, targetIntensity - negativeIntensity );
}
}
}

targetIntensity *= m_intensityMultiplier;

if( m_minimumTransitionTime <= 0.f )
{
m_postProcessAttributes->intensity = targetIntensity;
}
else if( m_postProcessAttributes->intensity != targetIntensity )
{
float diff = targetIntensity - m_postProcessAttributes->intensity;
float lerpSpeed = std::max( std::max( abs( m_intensityMultiplier ), abs( diff ) ), 1.f );
float maxDiff = updateContext.GetDeltaT() * ( 1.0f / m_minimumTransitionTime ) * lerpSpeed;
diff = max( -maxDiff, min( diff, maxDiff ) );
m_postProcessAttributes->intensity += diff;
}
}

void EveChildPostProcessVolume::UpdateTransformFromParent( const EveChildUpdateParams& params )
Expand Down
4 changes: 4 additions & 0 deletions trinity/Eve/SpaceObject/Children/EveChildPostProcessVolume.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ BLUE_CLASS( EveChildPostProcessVolume ) :

CcpMath::Sphere m_boundingSphere;

bool m_enabled;
float m_intensityMultiplier;
Comment thread
filipppavlov marked this conversation as resolved.
float m_minimumTransitionTime;

// post process attributes
Tr2PostProcessAttributesPtr m_postProcessAttributes;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const Be::ClassInfo* EveChildPostProcessVolume::ExposeToBlue()
MAP_INTERFACE( IInitialize )

MAP_ATTRIBUTE( "name", m_name, "", Be::READWRITE | Be::PERSIST )
MAP_ATTRIBUTE( "enabled", m_enabled, "Quickly disable all modifications. It will fade in/out using the minimumTransitionTime", Be::READWRITE | Be::PERSIST )
MAP_ATTRIBUTE( "intensityMultiplier", m_intensityMultiplier, "Param to scale/control/animate the modifications", Be::READWRITE | Be::PERSIST )
MAP_ATTRIBUTE( "minimumTransitionTime", m_minimumTransitionTime, "Seconds it takes to move between the min and max value", Be::READWRITE | Be::PERSIST )
MAP_ATTRIBUTE( "boundingSphereCenter", m_boundingSphere.center, "", Be::READ )
MAP_ATTRIBUTE( "boundingSphereRadius", m_boundingSphere.radius, "", Be::READ )
MAP_ATTRIBUTE( "volumes", m_volumes, "", Be::READ | Be::PERSIST )
Expand Down
Loading