void AHeatmapVisualizer::UpdateHeatmap(const FVector& AgentLocation)
{
UWorld* World = GetWorld();
// check if the render target, static mesh and material instance is valid
if(!HeatmapRenderTarget && !HeatmapMesh->GetStaticMesh() && !HeatmapMaterialInstance)
{
return; //TODO: Add better error handling
}
FTransform MeshTransform = HeatmapMesh->GetComponentTransform();
MeshTransform = MeshTransform.Inverse();
FLinearColor AgentPosOnToMesh = FLinearColor(MeshTransform.TransformPosition(AgentLocation));
FLinearColor outVal;
if(!AgentMaterialInstance->GetVectorParameterValue(FName("AgentPosition"), outVal))
{
UE_LOG(LogTemp, Error, TEXT("Failed to get the texture parameter value from the material instance"));
}
AgentMaterialInstance->SetVectorParameterValue(FName("AgentPosition"), AgentPosOnToMesh);
UKismetRenderingLibrary::DrawMaterialToRenderTarget(World, HeatmapRenderTarget, AgentMaterialInstance);
}
The code above draws to a render target that is being used to generate heatmaps, unfortunately graphic programming is something I know very little about. I know there are methods and check in this method that need to be placed elsewhere etc.
QUESTION
But what I need to know is how can I render to a 2D render target more efficiently, or render to another texture (basically this creates a grayscale material with circles on it white being location of agent and black where no agent is).
Quick Blurb
I’m using this texture rendering with mass ai so the need for performance is required when there is less than 500 agent locations it maintains 60fps which is ok but any more than that an it quickly ramps up, ie 1000 is unusable.
I know there are a few libraries out there that are supposed to be good for rendering to pngs and while i have not looked at them and happy to use if its the only way, but if it can be done efficiently in UE5 why add complexity.
GOAL
The agent target is 100,000 for this, but 10,000 is acceptable. I know that I will have to break maps up to zones etc but I’m a little stumped as to where to venture with this, obviously the current code needs an overhaul, but looking for pointers/recommendations/documentation/secrets/cheats
please help as this is for my masters and I am desperately running out of time