Skip to content
Snippets Groups Projects
Commit 029456fc authored by David Gilbert's avatar David Gilbert :bug:
Browse files

Merge branch 'feature/performance_opt' into 'develop'

Feature/performance opt

See merge request VR-Group/unreal-development/line-plugin!2
parents cb828d78 4eca72ec
Branches
No related tags found
No related merge requests found
File added
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
File added
...@@ -13,7 +13,7 @@ UGPUInstancedLineComponent::UGPUInstancedLineComponent(const FObjectInitializer& ...@@ -13,7 +13,7 @@ UGPUInstancedLineComponent::UGPUInstancedLineComponent(const FObjectInitializer&
CurrentTextureMarker = FIntPoint(0, 0); CurrentTextureMarker = FIntPoint(0, 0);
CurrentTextureIndex = 0, CurrentTextureIndex = 0,
NextFreeId = 0; //NextFreeId = 0;
TextureWidth = 2048; TextureWidth = 2048;
TextureHeight = 2048; TextureHeight = 2048;
...@@ -27,7 +27,7 @@ UGPUInstancedLineComponent::UGPUInstancedLineComponent(const FObjectInitializer& ...@@ -27,7 +27,7 @@ UGPUInstancedLineComponent::UGPUInstancedLineComponent(const FObjectInitializer&
SetCanEverAffectNavigation(false); SetCanEverAffectNavigation(false);
static ConstructorHelpers::FObjectFinder<UStaticMesh>LineMeshAsset(TEXT("StaticMesh'/InstancedMeshLineRendering/line.line'")); static ConstructorHelpers::FObjectFinder<UStaticMesh>LineMeshAsset(TEXT("StaticMesh'/InstancedMeshLineRendering/optimized_line.optimized_line'"));
static ConstructorHelpers::FObjectFinder<UMaterial>LineMaterialAsset(TEXT("Material'/InstancedMeshLineRendering/DynamicLineMaterial.DynamicLineMaterial'")); static ConstructorHelpers::FObjectFinder<UMaterial>LineMaterialAsset(TEXT("Material'/InstancedMeshLineRendering/DynamicLineMaterial.DynamicLineMaterial'"));
UStaticMesh* LineAsset = LineMeshAsset.Object; UStaticMesh* LineAsset = LineMeshAsset.Object;
UMaterial* LineMaterial = LineMaterialAsset.Object; UMaterial* LineMaterial = LineMaterialAsset.Object;
...@@ -513,6 +513,13 @@ void UGPUInstancedLineComponent::ReserveMemory(int32 NumberOfSegments, int32 Num ...@@ -513,6 +513,13 @@ void UGPUInstancedLineComponent::ReserveMemory(int32 NumberOfSegments, int32 Num
LinearLineData.Reserve(NumberOfLines * (NumberOfSegments + 1)); LinearLineData.Reserve(NumberOfLines * (NumberOfSegments + 1));
} }
void UGPUInstancedLineComponent::ReserveMemoryWithoutSegments(int32 NumberOfLines, int32 NumberOfTotalPoints)
{
PreAllocateInstancesMemory(NumberOfTotalPoints - NumberOfLines); // Allocates a bit too much
LineMap.Reserve(NumberOfTotalPoints - NumberOfLines);
LinearLineData.Reserve(NumberOfTotalPoints);
}
bool UGPUInstancedLineComponent::ResizeTexture(int32 Width, int32 Height) bool UGPUInstancedLineComponent::ResizeTexture(int32 Width, int32 Height)
{ {
if (LinearLineData.Num() > Width * Height) if (LinearLineData.Num() > Width * Height)
...@@ -531,9 +538,9 @@ bool UGPUInstancedLineComponent::ResizeTexture(int32 Width, int32 Height) ...@@ -531,9 +538,9 @@ bool UGPUInstancedLineComponent::ResizeTexture(int32 Width, int32 Height)
// This might be a bit awkward as the line map is a *map*, and not just an array. // This might be a bit awkward as the line map is a *map*, and not just an array.
// Some lines might be re-ordered in the texture, but that should be fine. // Some lines might be re-ordered in the texture, but that should be fine.
for(TPair<int32, FGPULineArray>& Line : LineMap) for(int32 LineId = 0; LineId < LineMap.Num(); ++LineId)// TPair<int32, FGPULineArray>& Line : LineMap)
{ {
for (FGPULineIndices& LineIndices : Line.Value.IndexArray) for (FGPULineIndices& LineIndices : LineMap[LineId].IndexArray)
{ {
// Key is instance id, value is texture index. // Key is instance id, value is texture index.
if(LineIndices.InstanceIndex >= 0) if(LineIndices.InstanceIndex >= 0)
...@@ -567,7 +574,7 @@ void UGPUInstancedLineComponent::InitializeLinesInBulk(int32 NumberOfLines, int3 ...@@ -567,7 +574,7 @@ void UGPUInstancedLineComponent::InitializeLinesInBulk(int32 NumberOfLines, int3
LinearLineData.Empty(); // Reset LinearLineData.Empty(); // Reset
LineMap.Empty(); LineMap.Empty();
NextFreeId = 0; //NextFreeId = 0;
CurrentTextureIndex = 0; CurrentTextureIndex = 0;
CurrentTextureMarker = FIntPoint(0, 0); CurrentTextureMarker = FIntPoint(0, 0);
ClearInstances(); ClearInstances();
...@@ -590,8 +597,8 @@ void UGPUInstancedLineComponent::InitializeLinesInBulk(int32 NumberOfLines, int3 ...@@ -590,8 +597,8 @@ void UGPUInstancedLineComponent::InitializeLinesInBulk(int32 NumberOfLines, int3
{ {
const FLinearColor Color = UniformColor ? Colors[0] : Colors[LineIndex]; const FLinearColor Color = UniformColor ? Colors[0] : Colors[LineIndex];
const float Width = UniformWidth ? Widths[0] : Widths[LineIndex]; const float Width = UniformWidth ? Widths[0] : Widths[LineIndex];
int32 Idx = LineMap.Add(FGPULineArray());
FGPULineArray& NewLineArray = LineMap.Add(NextFreeId, FGPULineArray()); FGPULineArray& NewLineArray = LineMap[Idx];
NewLineArray.IndexArray.Reserve(NumberOfSegmentsPerLine + 1); NewLineArray.IndexArray.Reserve(NumberOfSegmentsPerLine + 1);
for (int32 PointIndex = 0; PointIndex < NumberOfSegmentsPerLine; ++PointIndex) for (int32 PointIndex = 0; PointIndex < NumberOfSegmentsPerLine; ++PointIndex)
...@@ -601,7 +608,7 @@ void UGPUInstancedLineComponent::InitializeLinesInBulk(int32 NumberOfLines, int3 ...@@ -601,7 +608,7 @@ void UGPUInstancedLineComponent::InitializeLinesInBulk(int32 NumberOfLines, int3
SetCustomDataValue(InstanceId, 0, Color.R, false); SetCustomDataValue(InstanceId, 0, Color.R, false);
SetCustomDataValue(InstanceId, 1, Color.G, false); SetCustomDataValue(InstanceId, 1, Color.G, false);
SetCustomDataValue(InstanceId, 2, Color.B, false); SetCustomDataValue(InstanceId, 2, Color.B, false);
SetCustomDataValue(InstanceId, 3, Width, false); SetCustomDataValue(InstanceId, 3, Width / 2.0f, false);
SetCustomDataValue(InstanceId, 4, static_cast<float>(CurrentTextureIndex), false); // Segment Start SetCustomDataValue(InstanceId, 4, static_cast<float>(CurrentTextureIndex), false); // Segment Start
NewLineArray.IndexArray.Add({InstanceId, LineIndex * (NumberOfSegmentsPerLine + 1) + PointIndex}); NewLineArray.IndexArray.Add({InstanceId, LineIndex * (NumberOfSegmentsPerLine + 1) + PointIndex});
CurrentTextureIndex++; CurrentTextureIndex++;
...@@ -611,7 +618,7 @@ void UGPUInstancedLineComponent::InitializeLinesInBulk(int32 NumberOfLines, int3 ...@@ -611,7 +618,7 @@ void UGPUInstancedLineComponent::InitializeLinesInBulk(int32 NumberOfLines, int3
NewLineArray.IndexArray.Add({-1, LineIndex * (NumberOfSegmentsPerLine + 1) + NumberOfSegmentsPerLine}); NewLineArray.IndexArray.Add({-1, LineIndex * (NumberOfSegmentsPerLine + 1) + NumberOfSegmentsPerLine});
MoveTextureMarker(); MoveTextureMarker();
CurrentTextureIndex++; CurrentTextureIndex++;
NextFreeId++; //NextFreeId++;
} }
MarkRenderStateDirty(); MarkRenderStateDirty();
...@@ -627,11 +634,12 @@ int32 UGPUInstancedLineComponent::AddLine(const TArray<FVector>& Line, FLinearCo ...@@ -627,11 +634,12 @@ int32 UGPUInstancedLineComponent::AddLine(const TArray<FVector>& Line, FLinearCo
return -1; return -1;
} }
// 1. // 1.
FGPULineArray& NewLineArray = LineMap.Add(NextFreeId, FGPULineArray()); const int32 LineId = LineMap.Add(FGPULineArray());
FGPULineArray& NewLineArray = LineMap[LineId];
NewLineArray.IndexArray.Reserve(Line.Num()); NewLineArray.IndexArray.Reserve(Line.Num());
const int32 LineId = NextFreeId; //const int32 LineId = NextFreeId;
NextFreeId++; // TODO Fix Id system as this can possibly overflow. //NextFreeId++; // TODO Fix Id system as this can possibly overflow.
...@@ -646,7 +654,7 @@ int32 UGPUInstancedLineComponent::AddLine(const TArray<FVector>& Line, FLinearCo ...@@ -646,7 +654,7 @@ int32 UGPUInstancedLineComponent::AddLine(const TArray<FVector>& Line, FLinearCo
SetCustomDataValue(InstanceId, 0, Color.R, false); SetCustomDataValue(InstanceId, 0, Color.R, false);
SetCustomDataValue(InstanceId, 1, Color.G, false); SetCustomDataValue(InstanceId, 1, Color.G, false);
SetCustomDataValue(InstanceId, 2, Color.B, false); SetCustomDataValue(InstanceId, 2, Color.B, false);
SetCustomDataValue(InstanceId, 3, Width, false); SetCustomDataValue(InstanceId, 3, Width / 2.0f, false);
SetCustomDataValue(InstanceId, 4, static_cast<float>(CurrentTextureIndex), false); // Segment Start SetCustomDataValue(InstanceId, 4, static_cast<float>(CurrentTextureIndex), false); // Segment Start
NewLineArray.IndexArray.Add({InstanceId, LinearLineData.Num() + PointIndex}); NewLineArray.IndexArray.Add({InstanceId, LinearLineData.Num() + PointIndex});
CurrentTextureIndex++; CurrentTextureIndex++;
...@@ -685,6 +693,70 @@ int32 UGPUInstancedLineComponent::AddLine(const TArray<FVector>& Line, FLinearCo ...@@ -685,6 +693,70 @@ int32 UGPUInstancedLineComponent::AddLine(const TArray<FVector>& Line, FLinearCo
return LineId; return LineId;
} }
int32 UGPUInstancedLineComponent::AddLine(TArray<FVector4>& Line, FLinearColor Color, float Width)
{
if (Line.Num() < 2)
{
UE_LOG(LogLineRendering, Error, TEXT("UGPUInstancedLineComponent::AddLine : Can't add line with less than 2 points.")); // Actually we can!
return -1;
}
// 1.
const int32 LineId = LineMap.Add(FGPULineArray());
FGPULineArray& NewLineArray = LineMap[LineId];
NewLineArray.IndexArray.Reserve(Line.Num());
const int32 NumberSegments = Line.Num() - 1;
const FIntPoint InitialTextureMarker = CurrentTextureMarker;
for (int32 PointIndex = 0; PointIndex < NumberSegments; ++PointIndex)
{
// Add with a dummy transform
int32 InstanceId = AddInstance(FTransform::Identity);
SetCustomDataValue(InstanceId, 0, Color.R, false);
SetCustomDataValue(InstanceId, 1, Color.G, false);
SetCustomDataValue(InstanceId, 2, Color.B, false);
SetCustomDataValue(InstanceId, 3, Width / 2.0f, false);
SetCustomDataValue(InstanceId, 4, static_cast<float>(CurrentTextureIndex), false); // Segment Start
NewLineArray.IndexArray.Add({ InstanceId, LinearLineData.Num() + PointIndex });
CurrentTextureIndex++;
MoveTextureMarker();
}
// Add the last point which does not correspond to a transform/instance, but needs to be added to the texture still such that the second last instance can read it:
NewLineArray.IndexArray.Add({ -1, LinearLineData.Num() + NumberSegments });
MoveTextureMarker();
CurrentTextureIndex++;
// Recreate the data on the heap to allow asynchronous texture update.
TArray<FVector4>* TextureData = new TArray<FVector4>(MoveTemp(Line));
// Store the points in a linear array here
LinearLineData.Append(*TextureData);
int32 NumRegions = 0;
FUpdateTextureRegion2D* Regions = CalculateTextureRegions(InitialTextureMarker, TextureData->Num(), NumRegions);
const uint32 Pitch = TextureWidth;
PositionTexture->UpdateTextureRegions(0, NumRegions, Regions, Pitch * sizeof(FVector4), sizeof(FVector4), (uint8*)TextureData->GetData(),
[](auto InTextureData, auto InRegions)
{
// Clean up the copied data
delete InTextureData;
delete InRegions;
});
//UE_LOG(LogLineRendering, Display, TEXT("Added Line #%d"), LineId); // Actually we can!
return LineId;
}
int32 UGPUInstancedLineComponent::AddLineFromEditorData(FEditorLineData& LineData) int32 UGPUInstancedLineComponent::AddLineFromEditorData(FEditorLineData& LineData)
{ {
const TArray<FEditorPoint>* EditorLineDataPtr = &LineData.Points; const TArray<FEditorPoint>* EditorLineDataPtr = &LineData.Points;
...@@ -721,7 +793,7 @@ bool UGPUInstancedLineComponent::AddPoint(int32 LineId, const FVector& Point) ...@@ -721,7 +793,7 @@ bool UGPUInstancedLineComponent::AddPoint(int32 LineId, const FVector& Point)
SetCustomDataValue(InstanceId, 0, R, false); SetCustomDataValue(InstanceId, 0, R, false);
SetCustomDataValue(InstanceId, 1, G, false); SetCustomDataValue(InstanceId, 1, G, false);
SetCustomDataValue(InstanceId, 2, B, false); SetCustomDataValue(InstanceId, 2, B, false);
SetCustomDataValue(InstanceId, 3, Width, false); SetCustomDataValue(InstanceId, 3, Width / 2.0f, false);
// Update the latest dummy entry to point to the actual segment. // Update the latest dummy entry to point to the actual segment.
Line.IndexArray.Last().InstanceIndex = InstanceId; Line.IndexArray.Last().InstanceIndex = InstanceId;
...@@ -731,7 +803,7 @@ bool UGPUInstancedLineComponent::AddPoint(int32 LineId, const FVector& Point) ...@@ -731,7 +803,7 @@ bool UGPUInstancedLineComponent::AddPoint(int32 LineId, const FVector& Point)
FVector4& PreviousLastPoint = LinearLineData[Indices.TextureIndex]; FVector4& PreviousLastPoint = LinearLineData[Indices.TextureIndex];
PreviousLastPoint.W = 1.0; // This isn't the line end anymore. PreviousLastPoint.W = 1.0; // This isn't the line end anymore.
if(LineId == NextFreeId - 1) if(LineId == LineMap.Num() - 1)
{ {
LinearLineData.Add(FVector4(Point, -1)); // This is the last point now. LinearLineData.Add(FVector4(Point, -1)); // This is the last point now.
...@@ -793,10 +865,10 @@ bool UGPUInstancedLineComponent::AddPoint(int32 LineId, const FVector& Point) ...@@ -793,10 +865,10 @@ bool UGPUInstancedLineComponent::AddPoint(int32 LineId, const FVector& Point)
const int32 NewPointTextureIndex = Indices.TextureIndex + 1; const int32 NewPointTextureIndex = Indices.TextureIndex + 1;
// Update all LineMap Indices that have a texture index larger than the newly inserted point. Todo: Make more efficient, maybe remove map and swap to array: // Update all LineMap Indices that have a texture index larger than the newly inserted point.
for (TPair<int32, FGPULineArray>& Pair : LineMap) //Todo: Make more efficient
for (FGPULineArray& LineArray : LineMap)
{ {
FGPULineArray& LineArray = Pair.Value;
if (LineArray.IndexArray[0].TextureIndex >= NewPointTextureIndex) if (LineArray.IndexArray[0].TextureIndex >= NewPointTextureIndex)
{ {
// Need to increase all indices by 1 and adjust the custom data // Need to increase all indices by 1 and adjust the custom data
...@@ -842,7 +914,7 @@ bool UGPUInstancedLineComponent::InsertPoint(int32 LineId, int32 SegmentId, cons ...@@ -842,7 +914,7 @@ bool UGPUInstancedLineComponent::InsertPoint(int32 LineId, int32 SegmentId, cons
SetCustomDataValue(InstanceId, 0, Color.R, false); SetCustomDataValue(InstanceId, 0, Color.R, false);
SetCustomDataValue(InstanceId, 1, Color.G, false); SetCustomDataValue(InstanceId, 1, Color.G, false);
SetCustomDataValue(InstanceId, 2, Color.B, false); SetCustomDataValue(InstanceId, 2, Color.B, false);
SetCustomDataValue(InstanceId, 3, Width, false); SetCustomDataValue(InstanceId, 3, Width / 2.0f, false);
LinearLineData.Insert(FVector4(Point), LinearDataIndex); LinearLineData.Insert(FVector4(Point), LinearDataIndex);
...@@ -865,9 +937,8 @@ bool UGPUInstancedLineComponent::InsertPoint(int32 LineId, int32 SegmentId, cons ...@@ -865,9 +937,8 @@ bool UGPUInstancedLineComponent::InsertPoint(int32 LineId, int32 SegmentId, cons
} }
// Update all following lines // Update all following lines
for (TPair<int32, FGPULineArray>& Pair : LineMap) for (FGPULineArray& LineArray : LineMap)
{ {
FGPULineArray& LineArray = Pair.Value;
if (LineArray.IndexArray[0].TextureIndex > LinearDataIndex) if (LineArray.IndexArray[0].TextureIndex > LinearDataIndex)
{ {
// Need to increase all indices by 1 and adjust the custom data // Need to increase all indices by 1 and adjust the custom data
...@@ -927,7 +998,7 @@ bool UGPUInstancedLineComponent::AddPoints(int32 LineId, const TArray<FVector>& ...@@ -927,7 +998,7 @@ bool UGPUInstancedLineComponent::AddPoints(int32 LineId, const TArray<FVector>&
FVector4& PreviousLastPoint = LinearLineData[Indices.TextureIndex]; FVector4& PreviousLastPoint = LinearLineData[Indices.TextureIndex];
PreviousLastPoint.W = 1.0; // This isn't the line end anymore. PreviousLastPoint.W = 1.0; // This isn't the line end anymore.
if (LineId == NextFreeId - 1) if (LineId == LineMap.Num() - 1)
{ {
for (int32 PointIndex = 0; PointIndex < Points.Num(); ++PointIndex) for (int32 PointIndex = 0; PointIndex < Points.Num(); ++PointIndex)
{ {
...@@ -936,7 +1007,7 @@ bool UGPUInstancedLineComponent::AddPoints(int32 LineId, const TArray<FVector>& ...@@ -936,7 +1007,7 @@ bool UGPUInstancedLineComponent::AddPoints(int32 LineId, const TArray<FVector>&
SetCustomDataValue(InstanceId, 0, R, false); SetCustomDataValue(InstanceId, 0, R, false);
SetCustomDataValue(InstanceId, 1, G, false); SetCustomDataValue(InstanceId, 1, G, false);
SetCustomDataValue(InstanceId, 2, B, false); SetCustomDataValue(InstanceId, 2, B, false);
SetCustomDataValue(InstanceId, 3, Width, false); SetCustomDataValue(InstanceId, 3, Width / 2.0f, false);
SetCustomDataValue(InstanceId, 4, static_cast<float>(PointTextureIndex + PointIndex), false); SetCustomDataValue(InstanceId, 4, static_cast<float>(PointTextureIndex + PointIndex), false);
// Update the latest dummy entry to point to the actual segment. // Update the latest dummy entry to point to the actual segment.
...@@ -987,9 +1058,8 @@ bool UGPUInstancedLineComponent::AddPoints(int32 LineId, const TArray<FVector>& ...@@ -987,9 +1058,8 @@ bool UGPUInstancedLineComponent::AddPoints(int32 LineId, const TArray<FVector>&
const int32 NewPointTextureIndex = Indices.TextureIndex + 1; const int32 NewPointTextureIndex = Indices.TextureIndex + 1;
// Update all LineMap Indices that have a texture index larger than the newly inserted point. Todo: Make more efficient, maybe remove map and swap to array: // Update all LineMap Indices that have a texture index larger than the newly inserted point. Todo: Make more efficient, maybe remove map and swap to array:
for (TPair<int32, FGPULineArray>& Pair : LineMap) for (FGPULineArray& LineArray : LineMap)
{ {
FGPULineArray& LineArray = Pair.Value;
if (LineArray.IndexArray[0].TextureIndex >= NewPointTextureIndex) if (LineArray.IndexArray[0].TextureIndex >= NewPointTextureIndex)
{ {
// Need to increase all indices by 1 and adjust the custom data // Need to increase all indices by 1 and adjust the custom data
...@@ -1008,7 +1078,7 @@ bool UGPUInstancedLineComponent::AddPoints(int32 LineId, const TArray<FVector>& ...@@ -1008,7 +1078,7 @@ bool UGPUInstancedLineComponent::AddPoints(int32 LineId, const TArray<FVector>&
SetCustomDataValue(InstanceId, 0, R, false); SetCustomDataValue(InstanceId, 0, R, false);
SetCustomDataValue(InstanceId, 1, G, false); SetCustomDataValue(InstanceId, 1, G, false);
SetCustomDataValue(InstanceId, 2, B, false); SetCustomDataValue(InstanceId, 2, B, false);
SetCustomDataValue(InstanceId, 3, Width, false); SetCustomDataValue(InstanceId, 3, Width / 2.0f, false);
SetCustomDataValue(InstanceId, 4, static_cast<float>(NewPointTextureIndex - 1 + PointIndex), false); SetCustomDataValue(InstanceId, 4, static_cast<float>(NewPointTextureIndex - 1 + PointIndex), false);
// Update the latest dummy entry to point to the actual segment. // Update the latest dummy entry to point to the actual segment.
...@@ -1073,7 +1143,7 @@ bool UGPUInstancedLineComponent::InsertPoints(int32 LineId, int32 SegmentId, con ...@@ -1073,7 +1143,7 @@ bool UGPUInstancedLineComponent::InsertPoints(int32 LineId, int32 SegmentId, con
SetCustomDataValue(InstanceId, 0, R, false); SetCustomDataValue(InstanceId, 0, R, false);
SetCustomDataValue(InstanceId, 1, G, false); SetCustomDataValue(InstanceId, 1, G, false);
SetCustomDataValue(InstanceId, 2, B, false); SetCustomDataValue(InstanceId, 2, B, false);
SetCustomDataValue(InstanceId, 3, Width, false); SetCustomDataValue(InstanceId, 3, Width / 2.0f, false);
Line.IndexArray.Insert({ InstanceId, LinearDataIndex + PointIndex }, SegmentId + PointIndex); Line.IndexArray.Insert({ InstanceId, LinearDataIndex + PointIndex }, SegmentId + PointIndex);
SetCustomDataValue(InstanceId, 4, LinearDataIndex + PointIndex, false); SetCustomDataValue(InstanceId, 4, LinearDataIndex + PointIndex, false);
...@@ -1089,9 +1159,9 @@ bool UGPUInstancedLineComponent::InsertPoints(int32 LineId, int32 SegmentId, con ...@@ -1089,9 +1159,9 @@ bool UGPUInstancedLineComponent::InsertPoints(int32 LineId, int32 SegmentId, con
} }
// Update all following lines // Update all following lines
for (TPair<int32, FGPULineArray>& Pair : LineMap) for (FGPULineArray& LineArray : LineMap)
{ {
FGPULineArray& LineArray = Pair.Value; //FGPULineArray& LineArray = Pair.Value;
if (LineArray.IndexArray[0].TextureIndex > LinearDataIndex) if (LineArray.IndexArray[0].TextureIndex > LinearDataIndex)
{ {
// Need to increase all indices by 1 and adjust the custom data // Need to increase all indices by 1 and adjust the custom data
...@@ -1376,12 +1446,12 @@ bool UGPUInstancedLineComponent::RemoveLine(int32 LineId) ...@@ -1376,12 +1446,12 @@ bool UGPUInstancedLineComponent::RemoveLine(int32 LineId)
// Remove linear data: // Remove linear data:
LinearLineData.RemoveAt(LineTextureIndex, LineLength); LinearLineData.RemoveAt(LineTextureIndex, LineLength);
// Remove line from map, this invalidates above Line reference. // Remove line from map, this invalidates above Line reference.
LineMap.Remove(LineId); LineMap.RemoveAt(LineId);
// Update all following lines // Update all following lines
for (TPair<int32, FGPULineArray>& Pair : LineMap) for (FGPULineArray& LineArray : LineMap)
{ {
FGPULineArray& LineArray = Pair.Value; //FGPULineArray& LineArray = Pair.Value;
for (int32 i = 0; i < LineArray.IndexArray.Num(); ++i) for (int32 i = 0; i < LineArray.IndexArray.Num(); ++i)
{ {
if (LineArray.IndexArray[i].InstanceIndex >= InstancesToRemove[0]) if (LineArray.IndexArray[i].InstanceIndex >= InstancesToRemove[0])
...@@ -1480,9 +1550,8 @@ bool UGPUInstancedLineComponent::RemovePoint(int32 LineId, int32 PointId) ...@@ -1480,9 +1550,8 @@ bool UGPUInstancedLineComponent::RemovePoint(int32 LineId, int32 PointId)
Line.IndexArray.RemoveAt(PointId); Line.IndexArray.RemoveAt(PointId);
// Update all following lines // Update all following lines
for (TPair<int32, FGPULineArray>& Pair : LineMap) for (FGPULineArray& LineArray : LineMap)
{ {
FGPULineArray& LineArray = Pair.Value;
for (int32 i = 0; i < LineArray.IndexArray.Num(); ++i) for (int32 i = 0; i < LineArray.IndexArray.Num(); ++i)
{ {
if (LineArray.IndexArray[i].InstanceIndex >= RemovedInstanceId) if (LineArray.IndexArray[i].InstanceIndex >= RemovedInstanceId)
...@@ -1558,7 +1627,7 @@ bool UGPUInstancedLineComponent::SetLineWidth(int32 LineId, float Width) ...@@ -1558,7 +1627,7 @@ bool UGPUInstancedLineComponent::SetLineWidth(int32 LineId, float Width)
const int32 InstanceId = LineIndices.InstanceIndex; const int32 InstanceId = LineIndices.InstanceIndex;
if (InstanceId >= 0) if (InstanceId >= 0)
{ {
SetCustomDataValue(InstanceId, 3, Width, false); SetCustomDataValue(InstanceId, 3, Width / 2.0f, false);
} }
} }
MarkRenderStateDirty(); MarkRenderStateDirty();
...@@ -1569,7 +1638,7 @@ bool UGPUInstancedLineComponent::SetSegmentWidth(int32 LineId, int32 SegmentId, ...@@ -1569,7 +1638,7 @@ bool UGPUInstancedLineComponent::SetSegmentWidth(int32 LineId, int32 SegmentId,
{ {
const int32 InstanceId = LineMap[LineId].IndexArray[SegmentId].InstanceIndex; const int32 InstanceId = LineMap[LineId].IndexArray[SegmentId].InstanceIndex;
SetCustomDataValue(InstanceId, 3, Width, false); SetCustomDataValue(InstanceId, 3, Width / 2.0f, false);
return true; return true;
} }
//#pragma optimize("", on) //#pragma optimize("", on)
...@@ -155,6 +155,10 @@ public: ...@@ -155,6 +155,10 @@ public:
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent") UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
void ReserveMemory(int32 NumberOfSegments, int32 NumberOfLines); void ReserveMemory(int32 NumberOfSegments, int32 NumberOfLines);
void ReserveMemoryWithoutSegments(int32 NumberOfLines, int32 NumberOfTotalPoints);
/** /**
* Manually resized the texture to the specified width and height. Returns false if the texture couldn't be resized, e.g. if more lines are * Manually resized the texture to the specified width and height. Returns false if the texture couldn't be resized, e.g. if more lines are
* being rendered than can be displayed in the texture. * being rendered than can be displayed in the texture.
...@@ -198,6 +202,9 @@ public: ...@@ -198,6 +202,9 @@ public:
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent") UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
int32 AddLine(const TArray<FVector>& Line, FLinearColor Color, float Width = 1.0); int32 AddLine(const TArray<FVector>& Line, FLinearColor Color, float Width = 1.0);
int32 AddLine(TArray<FVector4>& Line, FLinearColor Color, float Width = 1.0);
/** /**
* Adds a line and returns the respective ID of the line, which can be used to identify it for updating, modifying and removing. * Adds a line and returns the respective ID of the line, which can be used to identify it for updating, modifying and removing.
* *
...@@ -462,7 +469,7 @@ public: ...@@ -462,7 +469,7 @@ public:
UMaterialInterface* LineMaterialInterface; UMaterialInterface* LineMaterialInterface;
UPROPERTY() UPROPERTY()
TMap<int32, FGPULineArray> LineMap; TArray<FGPULineArray> LineMap;
//private: //private:
...@@ -475,8 +482,8 @@ public: ...@@ -475,8 +482,8 @@ public:
UPROPERTY() UPROPERTY()
TArray<int32> EditorLineIds; TArray<int32> EditorLineIds;
UPROPERTY() //UPROPERTY()
int32 NextFreeId; //int32 NextFreeId;
UPROPERTY() UPROPERTY()
int32 CurrentTextureIndex; int32 CurrentTextureIndex;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment