Hi,
I am trying to write a custom material for the CARLA Simulator (in version 0.9.11) to display pixel-accurate object IDs in the rendered image. For this I want to use custom primitive data as an parameter in my custom material to write the IDs to. In a first attempt I used a preexisting material called “GTMaterial” which renders object class labels (like “Car”, “Pedestrian”, etc.) using a custom depth stencil value. Everything in the next image going into input B of the final “Multiply” node is the preexisting material:
If I use the custom primitive data as a masking value, the whole image stays black, but if I use a static value of 1 from Param_1 the image renders normally. I have tried several indices to write the custom data to, to rule out that I accidentally use an index which is already in use. (The image shows index 7, but index 0 did not work either).
The code to set the custom depth stencil and custom primitive data is this:
void ATagger::SetStencilValue(
UPrimitiveComponent &Component,
const crp::CityObjectLabel &Label,
const bool bSetRenderCustomDepth)
{
Component.SetCustomDepthStencilValue(CastEnum(Label));
UE_LOG(LogCarla, Log, TEXT("IMPORTANT: CUSTOM DATA"));
Component.SetCustomPrimitiveDataFloat(0, 1.f);
auto data = Component.GetCustomPrimitiveData().Data;
int idx = 0;
for (auto item : data)
{
UE_LOG(LogCarla, Log, TEXT(" !!!CUSTOM DATA %i, %f"), idx, item);
++idx;
}
Component.SetRenderCustomDepth(
bSetRenderCustomDepth &&
(Label != crp::CityObjectLabel::None));
}
void ATagger::TagActor(const AActor &Actor, bool bTagForSemanticSegmentation)
{
// Iterate static meshes.
TArray<UStaticMeshComponent *> StaticMeshComponents;
Actor.GetComponents<UStaticMeshComponent>(StaticMeshComponents);
for (UStaticMeshComponent *Component : StaticMeshComponents)
{
const auto Label = GetLabelByPath(Component->GetStaticMesh());
SetStencilValue(*Component, Label, bTagForSemanticSegmentation);
}
// Iterate skeletal meshes.
TArray<USkeletalMeshComponent *> SkeletalMeshComponents;
Actor.GetComponents<USkeletalMeshComponent>(SkeletalMeshComponents);
for (USkeletalMeshComponent *Component : SkeletalMeshComponents)
{
const auto Label = GetLabelByPath(Component->GetPhysicsAsset());
SetStencilValue(*Component, Label, bTagForSemanticSegmentation);
}
}
The UE_LOG statements indicate that the data seems to be written correctly.
My question is why my custom data seems to be always 0 inside the custom material and how to fix it. Any help would be much appreciated.