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
4 changes: 2 additions & 2 deletions trinity/Eve/EveEffectRoot2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void EveEffectRoot2::UpdateSyncronous( const EveUpdateContext& updateContext )

m_localTransform = TransformationMatrix( m_scaling, m_rotation, m_translation );
m_lastUpdateMatrix = m_localTransform * m_worldTransform;
m_secondaryLightingSphereRadiusWorld = m_secondaryLightingSphereRadiusLocal * ( m_scaling.x + m_scaling.y + m_scaling.z ) / 3.f;
m_secondaryLightingSphereRadiusWorld = m_secondaryLightingSphereRadiusLocal * ( std::abs( m_scaling.x ) + std::abs( m_scaling.y ) + std::abs( m_scaling.z ) ) / 3.f;

for( TriObserverLocalVector::iterator it = m_observers.begin(); it != m_observers.end(); ++it )
{
Expand Down Expand Up @@ -716,7 +716,7 @@ PEveSpaceObjectChildVector& EveEffectRoot2::GetChildren()
// -----------------------------------------------------------------------------
void EveEffectRoot2::SetTransform( const Matrix& transform )
{
Decompose( m_scaling, m_rotation, m_translation, transform );
DecomposeMirrorAware( m_scaling, m_rotation, m_translation, transform );
}

// -----------------------------------------------------------------------------
Expand Down
81 changes: 55 additions & 26 deletions trinity/Eve/EveInstancedMeshManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ ITriRenderBatchAccumulator* FindBatchAccumulator( const T& batches, TriBatchType
}
return nullptr;
}

constexpr uint32_t SLOTS_PER_LOD = 2;

uint32_t LodSlot( uint32_t lod, bool mirrored )
{
return lod * SLOTS_PER_LOD + ( mirrored ? 1u : 0u );
}

struct LodSlotDraw
{
TriGeometryResLodData* lodData = nullptr;
uint32_t primCount = 0;
TriGeometryAreaIndexRange indexRange;
bool valid = false;
};

LodSlotDraw GetLodSlotDraw( TriGeometryRes& geometry, uint32_t meshIndex, uint32_t areaIndex, uint32_t areaCount, bool areaReversed, uint32_t slot )
{
LodSlotDraw draw;
draw.lodData = geometry.GetMeshLod( meshIndex, int( slot / SLOTS_PER_LOD ) );
draw.primCount = GetPrimitiveCount( *draw.lodData, areaIndex, areaCount );
bool reversed = areaReversed != ( ( slot % SLOTS_PER_LOD ) != 0 );
draw.indexRange = GetAreaIndexRange( *draw.lodData, areaIndex, draw.primCount, reversed );
draw.valid = draw.primCount != 0 && draw.indexRange.valid;
return draw;
}
}


Expand All @@ -62,7 +88,7 @@ void EveInstancedMeshManager::CollectMeshes( EveComponentRegistry& registry )
{
m_perObjectDataBuffer.CreateInstance();
}
auto count = static_cast<uint32_t>( m_perObjectData.size() );
auto count = uint32_t( m_perObjectData.size() );
if( m_perObjectDataBuffer->GetCount() < count )
{
auto newCount = std::max( count, m_perObjectDataBuffer->GetCount() * 2u );
Expand Down Expand Up @@ -230,6 +256,7 @@ void EveInstancedMeshManager::AddMeshGroup(
meshIndex,
areaIndex,
areaCount,
false,
true };
auto& instances = m_meshInstances[key];
instances.material = material;
Expand All @@ -243,7 +270,7 @@ void EveInstancedMeshManager::AddMeshGroup(
{
auto meshData = geometry->GetMeshData( meshIndex );
auto lodCount = meshData->m_lods.size();
instances.lodIndices.resize( lodCount );
instances.lodIndices.resize( SLOTS_PER_LOD * lodCount );
instances.screenSizeThresholds.resize( lodCount );
for( uint32_t lod = 0; lod < lodCount; ++lod )
{
Expand Down Expand Up @@ -273,6 +300,7 @@ void EveInstancedMeshManager::AddMeshGroup(
uint32_t meshIndex,
uint32_t areaIndex,
uint32_t areaCount,
bool areaReversed,
Tr2Effect* material,
uint64_t materialHash,
const PerObjectDataHandle& perObjectDataHandle,
Expand All @@ -292,7 +320,8 @@ void EveInstancedMeshManager::AddMeshGroup(
batchType,
meshIndex,
areaIndex,
areaCount };
areaCount,
areaReversed };
auto& instances = m_meshInstances[key];
instances.material = material;
if( instances.radius == 0 )
Expand All @@ -305,7 +334,7 @@ void EveInstancedMeshManager::AddMeshGroup(
{
auto meshData = geometry->GetMeshData( meshIndex );
auto lodCount = meshData->m_lods.size();
instances.lodIndices.resize( lodCount );
instances.lodIndices.resize( SLOTS_PER_LOD * lodCount );
instances.screenSizeThresholds.resize( lodCount );
for( uint32_t lod = 0; lod < lodCount; ++lod )
{
Expand Down Expand Up @@ -653,7 +682,8 @@ std::pair<uint32_t, float> EveInstancedMeshManager::BinVisibleInstances( const M
maxScreenSize = std::max( maxScreenSize, screenSize );
if( screenSize > SCREEN_SIZE_THRESHOLD )
{
meshInfo.lodIndices[GetMeshLod( meshInfo, screenSize )].push_back( { mesh.isDynamic ? (const void*)&group.dynamicInstances[i] : (const void*)&group.staticInstances[i], group.perObjectDataIndex } );
bool mirrored = mesh.isDynamic ? group.dynamicInstances[i].mirrored : group.staticInstances[i].mirrored;
meshInfo.lodIndices[LodSlot( GetMeshLod( meshInfo, screenSize ), mirrored )].push_back( { mesh.isDynamic ? (const void*)&group.dynamicInstances[i] : (const void*)&group.staticInstances[i], group.perObjectDataIndex } );
++totalCount;
}
}
Expand Down Expand Up @@ -807,31 +837,30 @@ void EveInstancedMeshManager::GetPickingBatches( EvePendingPickingReadback& read

for( uint32_t lod = 0; lod < static_cast<uint32_t>( meshInfo.lodIndices.size() ); ++lod )
{
traceback.push_back( { nullptr, 0 } );
if( meshInfo.lodIndices[lod].empty() )
{
continue;
}
InstanceBuffer::Allocation allocation = AllocateInstanceData( uint32_t( meshInfo.lodIndices[lod].size() ), mesh.isDynamic );
UploadLodData( mesh, meshInfo, lod, allocation );

auto lodData = mesh.geometry->GetMeshLod( mesh.meshIndex, int( lod ) );
auto primCount = GetPrimitiveCount( *lodData, mesh.areaIndex, mesh.areaCount );
if( !primCount )
auto draw = GetLodSlotDraw( *mesh.geometry, mesh.meshIndex, mesh.areaIndex, mesh.areaCount, mesh.areaReversed, lod );
if( !draw.valid )
{
continue;
}

uint32_t stride = uint32_t( mesh.isDynamic ? sizeof( DynamicPerInstanceBufferElement ) : sizeof( StaticPerInstanceBufferElement ) );

Tr2RenderBatch batch;
batch.SetMaterial( meshInfo.material );
batch.SetGeometry( mesh.combinedVertexDeclaration, lodData->m_vertexAllocation, lodData->m_indexAllocation );
batch.SetGeometry( mesh.combinedVertexDeclaration, draw.lodData->m_vertexAllocation, *draw.indexRange.indices );
batch.SetStreamSource( 1, *allocation.buffer, stride );
batch.SetDrawIndexedInstanced(
primCount * 3,
draw.primCount * 3,
static_cast<uint32_t>( meshInfo.lodIndices[lod].size() ),
lodData->m_indexAllocation.GetStartIndex() + lodData->m_areas[mesh.areaIndex].m_firstIndex,
lodData->m_vertexAllocation.GetOffset() / lodData->m_vertexAllocation.GetStride(),
draw.indexRange.startIndex,
draw.lodData->m_vertexAllocation.GetOffset() / draw.lodData->m_vertexAllocation.GetStride(),
allocation.offset / stride );

auto perObjectData = accumulator->Allocate<PickingPerObjectData>();
Expand All @@ -840,7 +869,7 @@ void EveInstancedMeshManager::GetPickingBatches( EvePendingPickingReadback& read

accumulator->Commit( batch );

traceback.push_back( { group.owner, group.ownerIndex } );
traceback.back() = { group.owner, group.ownerIndex };
}
objectIdOffset += static_cast<uint32_t>( meshInfo.lodIndices.size() );
}
Expand Down Expand Up @@ -903,30 +932,30 @@ size_t EveInstancedMeshManager::GetBatches( const std::initializer_list<std::pai
{
continue;
}
uint32_t lodInstanceCount = uint32_t( meshInfo.lodIndices[lod].size() );

auto lodData = mesh.geometry->GetMeshLod( mesh.meshIndex, int( lod ) );

auto primCount = GetPrimitiveCount( *lodData, mesh.areaIndex, mesh.areaCount );
if( !primCount )
auto draw = GetLodSlotDraw( *mesh.geometry, mesh.meshIndex, mesh.areaIndex, mesh.areaCount, mesh.areaReversed, lod );
if( !draw.valid )
{
instanceOffset += lodInstanceCount;
continue;
}

Tr2RenderBatch batch;
batch.SetMaterial( meshInfo.material );
batch.SetGeometry( mesh.combinedVertexDeclaration, lodData->m_vertexAllocation, lodData->m_indexAllocation );
batch.SetGeometry( mesh.combinedVertexDeclaration, draw.lodData->m_vertexAllocation, *draw.indexRange.indices );
batch.SetStreamSource( 1, *allocation.buffer, stride );
batch.SetDrawIndexedInstanced(
primCount * 3,
static_cast<uint32_t>( meshInfo.lodIndices[lod].size() ),
lodData->m_indexAllocation.GetStartIndex() + lodData->m_areas[mesh.areaIndex].m_firstIndex,
lodData->m_vertexAllocation.GetOffset() / lodData->m_vertexAllocation.GetStride(),
draw.primCount * 3,
lodInstanceCount,
draw.indexRange.startIndex,
draw.lodData->m_vertexAllocation.GetOffset() / draw.lodData->m_vertexAllocation.GetStride(),
instanceOffset );

accumulator->Commit( batch );
instanceOffset += static_cast<uint32_t>( meshInfo.lodIndices[lod].size() );
instanceOffset += lodInstanceCount;

totalInstances += meshInfo.lodIndices[lod].size();
totalInstances += lodInstanceCount;
++totalBatches;
}
}
Expand Down Expand Up @@ -970,7 +999,7 @@ EveInstancedMeshManager::InstanceBuffer::Allocation EveInstancedMeshManager::All

uint32_t EveInstancedMeshManager::GetMeshLod( const MeshData& meshInfo, float screenSize )
{
auto lodCount = static_cast<uint32_t>( meshInfo.lodIndices.size() );
auto lodCount = static_cast<uint32_t>( meshInfo.screenSizeThresholds.size() );
for( uint32_t lod = 0; lod + 1 < lodCount; ++lod )
{
if( screenSize > meshInfo.screenSizeThresholds[lod + 1] )
Expand Down
5 changes: 5 additions & 0 deletions trinity/Eve/EveInstancedMeshManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ class EveInstancedMeshManager
Float4x3 worldTransform;
Float4x3 prevWorldTransform;
uint32_t sphereIndex = 0;
bool mirrored = false;
};

struct StaticPerInstanceData
{
Float4x3 worldTransform;
uint32_t sphereIndex = 0;
bool mirrored = false;
};

template <typename T>
Expand Down Expand Up @@ -128,6 +130,7 @@ class EveInstancedMeshManager
uint32_t meshIndex,
uint32_t areaIndex,
uint32_t areaCount,
bool areaReversed,
Tr2Effect* material,
uint64_t materialHash,
const PerObjectDataHandle& perObjectDataHandle,
Expand Down Expand Up @@ -162,6 +165,7 @@ class EveInstancedMeshManager
uint32_t meshIndex = 0;
uint32_t areaIndex = 0;
uint32_t areaCount = 1;
bool areaReversed = false;
bool isDynamic = false;

bool operator==( const MeshKey& other ) const
Expand All @@ -171,6 +175,7 @@ class EveInstancedMeshManager
meshIndex == other.meshIndex &&
areaIndex == other.areaIndex &&
areaCount == other.areaCount &&
areaReversed == other.areaReversed &&
materialHash == other.materialHash;
}
};
Expand Down
36 changes: 26 additions & 10 deletions trinity/Eve/SpaceObject/Attachments/EveMeshOverlayEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ static void EmitOverlayBatchesImpl(
TriBatchType batchType,
const OverlayEffectContainer& overlayEffects,
const std::vector<TriRenderBatchAreaBlock> ( &areaBlocks )[EveMeshOverlayEffect::TYPE_COUNT],
const TriGeometryResLodData& lod )
const TriGeometryResLodData& lod,
bool reverseWinding )
{
for( const auto& overlay : overlayEffects )
{
Expand All @@ -339,14 +340,20 @@ static void EmitOverlayBatchesImpl(
{
if( auto primCount = GetPrimitiveCount( lod, areaBlock.m_startIndex, areaBlock.m_count ) )
{
auto indexRange = GetAreaIndexRange( lod, areaBlock.m_startIndex, primCount, reverseWinding );
if( !indexRange.valid )
{
continue;
}

Tr2RenderBatch batch;
batch.SetMaterial( effect );
batch.SetGeometry( lod.m_mesh->m_vertexDeclarationHandle, lod.m_vertexAllocation, lod.m_indexAllocation );
batch.SetGeometry( lod.m_mesh->m_vertexDeclarationHandle, lod.m_vertexAllocation, *indexRange.indices );
batch.SetPerObjectData( perObjectData );
batch.SetDrawIndexedInstanced(
primCount * 3,
1,
lod.m_indexAllocation.GetStartIndex() + lod.m_areas[areaBlock.m_startIndex].m_firstIndex,
indexRange.startIndex,
lod.m_vertexAllocation.GetOffset() / lod.m_vertexAllocation.GetStride(),
0 );
batches->Commit( batch );
Expand All @@ -362,31 +369,39 @@ void EmitOverlayBatches(
TriBatchType batchType,
const PEveMeshOverlayEffectVector& overlayEffects,
const std::vector<TriRenderBatchAreaBlock> ( &areaBlocks )[EveMeshOverlayEffect::TYPE_COUNT],
const TriGeometryResLodData& lod )
const TriGeometryResLodData& lod,
bool reverseWinding )
{
EmitOverlayBatchesImpl( batches, perObjectData, batchType, overlayEffects, areaBlocks, lod );
EmitOverlayBatchesImpl( batches, perObjectData, batchType, overlayEffects, areaBlocks, lod, reverseWinding );
}

void EmitDamageOverlayBatches(
ITriRenderBatchAccumulator* batches,
const Tr2PerObjectData* perObjectData,
Tr2Effect* effect,
const std::vector<TriRenderBatchAreaBlock> ( &areaBlocks )[EveMeshOverlayEffect::TYPE_COUNT],
const TriGeometryResLodData& lod )
const TriGeometryResLodData& lod,
bool reverseWinding )
{
for( auto& areaBlock : areaBlocks[EveMeshOverlayEffect::TYPE_ALL] )
{
if( auto primCount = GetPrimitiveCount( lod, areaBlock.m_startIndex, areaBlock.m_count ) )
{
auto indexRange = GetAreaIndexRange( lod, areaBlock.m_startIndex, primCount, reverseWinding );
if( !indexRange.valid )
{
continue;
}

Tr2RenderBatch batch;
batch.SetMaterial( effect );
batch.SetPriority( 0xFFFFFFFF );
batch.SetGeometry( lod.m_mesh->m_vertexDeclarationHandle, lod.m_vertexAllocation, lod.m_indexAllocation );
batch.SetGeometry( lod.m_mesh->m_vertexDeclarationHandle, lod.m_vertexAllocation, *indexRange.indices );
batch.SetPerObjectData( perObjectData );
batch.SetDrawIndexedInstanced(
primCount * 3,
1,
lod.m_indexAllocation.GetStartIndex() + lod.m_areas[areaBlock.m_startIndex].m_firstIndex,
indexRange.startIndex,
lod.m_vertexAllocation.GetOffset() / lod.m_vertexAllocation.GetStride(),
0 );
batches->Commit( batch );
Expand All @@ -400,7 +415,8 @@ void EmitOverlayBatches(
TriBatchType batchType,
const std::vector<EveMeshOverlayEffectPtr>& overlayEffects,
const std::vector<TriRenderBatchAreaBlock> ( &areaBlocks )[EveMeshOverlayEffect::TYPE_COUNT],
const TriGeometryResLodData& lod )
const TriGeometryResLodData& lod,
bool reverseWinding )
{
EmitOverlayBatchesImpl( batches, perObjectData, batchType, overlayEffects, areaBlocks, lod );
EmitOverlayBatchesImpl( batches, perObjectData, batchType, overlayEffects, areaBlocks, lod, reverseWinding );
}
9 changes: 6 additions & 3 deletions trinity/Eve/SpaceObject/Attachments/EveMeshOverlayEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,24 @@ void EmitOverlayBatches(
TriBatchType batchType,
const PEveMeshOverlayEffectVector& overlayEffects,
const std::vector<TriRenderBatchAreaBlock> ( &areaBlocks )[EveMeshOverlayEffect::TYPE_COUNT],
const TriGeometryResLodData& lod );
const TriGeometryResLodData& lod,
bool reverseWinding = false );

void EmitOverlayBatches(
ITriRenderBatchAccumulator* batches,
const Tr2PerObjectData* perObjectData,
TriBatchType batchType,
const std::vector<EveMeshOverlayEffectPtr>& overlayEffects,
const std::vector<TriRenderBatchAreaBlock> ( &areaBlocks )[EveMeshOverlayEffect::TYPE_COUNT],
const TriGeometryResLodData& lod );
const TriGeometryResLodData& lod,
bool reverseWinding = false );

void EmitDamageOverlayBatches(
ITriRenderBatchAccumulator* batches,
const Tr2PerObjectData* perObjectData,
Tr2Effect* effect,
const std::vector<TriRenderBatchAreaBlock> ( &areaBlocks )[EveMeshOverlayEffect::TYPE_COUNT],
const TriGeometryResLodData& lod );
const TriGeometryResLodData& lod,
bool reverseWinding = false );

#endif // EveMeshOverlayEffect_H
4 changes: 3 additions & 1 deletion trinity/Eve/SpaceObject/Attachments/Sets/EveHazeSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ bool EveHazeSet::OnPrepareResources()
// --------------------------------------------------------------------------------------
bool EveHazeSet::UpdateVisibility( const EveUpdateContext& updateContext, const Matrix& parentTransform, const Float4x3* bones, size_t boneCount )
{
m_parentMirrored = IsMirrored( parentTransform );

auto aabb = GetItemSetAabb( m_aabb, m_boundingBoxes, bones, boneCount );
if( !aabb.IsInitialized() )
{
Expand Down Expand Up @@ -273,7 +275,7 @@ void EveHazeSet::GetBatches( ITriRenderBatchAccumulator* accumulator, TriBatchTy
return;
}

auto& indexBuffer = Tr2Renderer::GetQuadListIndexBuffer();
auto& indexBuffer = m_parentMirrored ? Tr2Renderer::GetReversedQuadListIndexBuffer() : Tr2Renderer::GetQuadListIndexBuffer();
if( !indexBuffer.IsValid() )
{
return;
Expand Down
2 changes: 2 additions & 0 deletions trinity/Eve/SpaceObject/Attachments/Sets/EveHazeSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ BLUE_CLASS( EveHazeSet ) :
unsigned int m_vertexCount;
Tr2SuballocatedBuffer::Allocation m_vertexBuffer;

bool m_parentMirrored = false;

// bounding box around static items
AxisAlignedBoundingBox m_aabb;
std::vector<std::pair<int, CcpMath::AxisAlignedBox>> m_boundingBoxes;
Expand Down
Loading
Loading