Skip to content

Commit

Permalink
Fixing up annotation sphere causing unwanted dark Lumen GI
Browse files Browse the repository at this point in the history
  • Loading branch information
WouterJansen committed Oct 2, 2024
1 parent 20bbc64 commit 8ef8c75
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 16 deletions.
Binary file modified Unreal/Plugins/AirSim/Content/HUDAssets/AnnotationMaterial.uasset
Binary file not shown.
Binary file not shown.
Binary file modified Unreal/Plugins/AirSim/Content/Models/AnnotationSphere.uasset
Binary file not shown.
Binary file modified Unreal/Plugins/AirSim/Content/Models/HiddenScaleMaterial.uasset
Binary file not shown.
56 changes: 41 additions & 15 deletions Unreal/Plugins/AirSim/Source/Annotation/AnnotationComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class FStaticAnnotationSceneProxy : public FStaticMeshSceneProxy
public:
FMaterialRenderProxy* MaterialRenderProxy;

//FStaticMeshSceneProxyDesc::InitializeFrom(UStaticMeshComponent* Component);

FStaticAnnotationSceneProxy(UStaticMeshComponent* Component, bool bForceLODsShareStaticLighting, UMaterialInterface* AnnotationMID) :
FStaticMeshSceneProxy(Component, bForceLODsShareStaticLighting)
{
Expand Down Expand Up @@ -187,8 +189,8 @@ UAnnotationComponent::UAnnotationComponent(const FObjectInitializer& ObjectIniti
{
bSkeletalMesh = false;
bTexture = false;
FString MaterialPath = TEXT("Material'/AirSim/HUDAssets/AnnotationMaterial.AnnotationMaterial'");

FString MaterialPath = TEXT("Material'/AirSim/HUDAssets/AnnotationMaterial.AnnotationMaterial'");
static ConstructorHelpers::FObjectFinder<UMaterial> AnnotationMaterialObject(*MaterialPath);
if (AnnotationMaterialObject.Object == nullptr)
{
Expand All @@ -198,6 +200,18 @@ UAnnotationComponent::UAnnotationComponent(const FObjectInitializer& ObjectIniti
{
AnnotationMaterial = AnnotationMaterialObject.Object;
}

FString MaterialPathSphere = TEXT("Material'/AirSim/HUDAssets/AnnotationMaterialSphere.AnnotationMaterialSphere'");
static ConstructorHelpers::FObjectFinder<UMaterial> SphereMaterialObject(*MaterialPathSphere);
if (SphereMaterialObject.Object == nullptr)
{
UE_LOG(LogTemp, Warning, TEXT("AirSim Annotation: Sphere annotation material is not valid."));
}
else
{
SphereMaterial = SphereMaterialObject.Object;
}

// ParentMeshInfo = MakeShareable(new FParentMeshInfo(nullptr));
// This will be invalid until attached to a MeshComponent
this->PrimaryComponentTick.bCanEverTick = true;
Expand All @@ -207,21 +221,33 @@ void UAnnotationComponent::OnRegister()
{
Super::OnRegister();

// Note: This can not be placed in the constructor, MID means material instance dynamic
AnnotationMID = UMaterialInstanceDynamic::Create(AnnotationMaterial, this, TEXT("AnnotationMaterialMID"));
if (!IsValid(AnnotationMID))
{
UE_LOG(LogTemp, Warning, TEXT("AirSim Annotation: ColorAnnotationMaterial is not correctly initialized"));
return;
if (this->GetFName().ToString().Contains("annotation_sphere")) {
AnnotationMID = UMaterialInstanceDynamic::Create(SphereMaterial, this, TEXT("AnnotationMaterialMID"));
if (!IsValid(AnnotationMID))
{
UE_LOG(LogTemp, Warning, TEXT("AirSim Annotation: SphereMaterial is not correctly initialized"));
return;
}
FLinearColor LinearAnnotationColor = FLinearColor(0, 0, 0, 1.0);
AnnotationMID->SetVectorParameterValue("AnnotationColor", LinearAnnotationColor);
}
else {
// Note: This can not be placed in the constructor, MID means material instance dynamic
AnnotationMID = UMaterialInstanceDynamic::Create(AnnotationMaterial, this, TEXT("AnnotationMaterialMID"));
if (!IsValid(AnnotationMID))
{
UE_LOG(LogTemp, Warning, TEXT("AirSim Annotation: ColorAnnotationMaterial is not correctly initialized"));
return;
}
const float OneOver255 = 1.0f / 255.0f;
FLinearColor LinearAnnotationColor = FLinearColor(
this->AnnotationColor.R * OneOver255,
this->AnnotationColor.G * OneOver255,
this->AnnotationColor.B * OneOver255,
1.0
);
AnnotationMID->SetVectorParameterValue("AnnotationColor", LinearAnnotationColor);
}
const float OneOver255 = 1.0f / 255.0f;
FLinearColor LinearAnnotationColor = FLinearColor(
this->AnnotationColor.R * OneOver255,
this->AnnotationColor.G * OneOver255,
this->AnnotationColor.B * OneOver255,
1.0
);
AnnotationMID->SetVectorParameterValue("AnnotationColor", LinearAnnotationColor);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class AIRSIM_API UAnnotationComponent : public UPrimitiveComponent

UPROPERTY()
UMaterial* AnnotationMaterial;
UMaterial* SphereMaterial;

UPROPERTY()
UMaterialInstanceDynamic* AnnotationMID;
Expand Down
1 change: 0 additions & 1 deletion Unreal/Plugins/AirSim/Source/PIPCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,6 @@ void APIPCamera::addAnnotationCamera(FString name, FObjectAnnotator::AnnotatorTy
UAnnotationComponent* AnnotationComponent = NewObject<UAnnotationComponent>(annotation_sphere, FName(*annotatedSphereName));
AnnotationComponent->SetupAttachment(annotation_sphere);
AnnotationComponent->RegisterComponent();
AnnotationComponent->SetAnnotationColor(FColor(0, 0, 0));
AnnotationComponent->MarkRenderStateDirty();
UPrimitiveComponent* PrimitiveComponent = Cast<UPrimitiveComponent>(AnnotationComponent);

Expand Down

0 comments on commit 8ef8c75

Please sign in to comment.