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

Reduced vertex shader instruction count by approx. 10% via:

- added new line mesh that has vertices at positions that can be directly multiplied
- pre-divided line width and removed some unnecessary division in pixel shader
Todo:
- look at better distance field computation
- look into better texture index computation to get rid of if there
parent cb828d78
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
......@@ -27,7 +27,7 @@ UGPUInstancedLineComponent::UGPUInstancedLineComponent(const FObjectInitializer&
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'"));
UStaticMesh* LineAsset = LineMeshAsset.Object;
UMaterial* LineMaterial = LineMaterialAsset.Object;
......@@ -601,7 +601,7 @@ void UGPUInstancedLineComponent::InitializeLinesInBulk(int32 NumberOfLines, int3
SetCustomDataValue(InstanceId, 0, Color.R, false);
SetCustomDataValue(InstanceId, 1, Color.G, 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
NewLineArray.IndexArray.Add({InstanceId, LineIndex * (NumberOfSegmentsPerLine + 1) + PointIndex});
CurrentTextureIndex++;
......@@ -646,7 +646,7 @@ int32 UGPUInstancedLineComponent::AddLine(const TArray<FVector>& Line, FLinearCo
SetCustomDataValue(InstanceId, 0, Color.R, false);
SetCustomDataValue(InstanceId, 1, Color.G, 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
NewLineArray.IndexArray.Add({InstanceId, LinearLineData.Num() + PointIndex});
CurrentTextureIndex++;
......@@ -721,7 +721,7 @@ bool UGPUInstancedLineComponent::AddPoint(int32 LineId, const FVector& Point)
SetCustomDataValue(InstanceId, 0, R, false);
SetCustomDataValue(InstanceId, 1, G, 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.
Line.IndexArray.Last().InstanceIndex = InstanceId;
......@@ -842,7 +842,7 @@ bool UGPUInstancedLineComponent::InsertPoint(int32 LineId, int32 SegmentId, cons
SetCustomDataValue(InstanceId, 0, Color.R, false);
SetCustomDataValue(InstanceId, 1, Color.G, false);
SetCustomDataValue(InstanceId, 2, Color.B, false);
SetCustomDataValue(InstanceId, 3, Width, false);
SetCustomDataValue(InstanceId, 3, Width / 2.0f, false);
LinearLineData.Insert(FVector4(Point), LinearDataIndex);
......@@ -936,7 +936,7 @@ bool UGPUInstancedLineComponent::AddPoints(int32 LineId, const TArray<FVector>&
SetCustomDataValue(InstanceId, 0, R, false);
SetCustomDataValue(InstanceId, 1, G, 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);
// Update the latest dummy entry to point to the actual segment.
......@@ -1008,7 +1008,7 @@ bool UGPUInstancedLineComponent::AddPoints(int32 LineId, const TArray<FVector>&
SetCustomDataValue(InstanceId, 0, R, false);
SetCustomDataValue(InstanceId, 1, G, 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);
// Update the latest dummy entry to point to the actual segment.
......@@ -1073,7 +1073,7 @@ bool UGPUInstancedLineComponent::InsertPoints(int32 LineId, int32 SegmentId, con
SetCustomDataValue(InstanceId, 0, R, false);
SetCustomDataValue(InstanceId, 1, G, 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);
SetCustomDataValue(InstanceId, 4, LinearDataIndex + PointIndex, false);
......@@ -1558,7 +1558,7 @@ bool UGPUInstancedLineComponent::SetLineWidth(int32 LineId, float Width)
const int32 InstanceId = LineIndices.InstanceIndex;
if (InstanceId >= 0)
{
SetCustomDataValue(InstanceId, 3, Width, false);
SetCustomDataValue(InstanceId, 3, Width / 2.0f, false);
}
}
MarkRenderStateDirty();
......@@ -1569,7 +1569,7 @@ bool UGPUInstancedLineComponent::SetSegmentWidth(int32 LineId, int32 SegmentId,
{
const int32 InstanceId = LineMap[LineId].IndexArray[SegmentId].InstanceIndex;
SetCustomDataValue(InstanceId, 3, Width, false);
SetCustomDataValue(InstanceId, 3, Width / 2.0f, false);
return true;
}
//#pragma optimize("", on)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment