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

Material optimizations

parent fb01e56a
Branches
No related tags found
No related merge requests found
No preview for this file type
File added
No preview for this file type
...@@ -197,7 +197,6 @@ void AOptiXLaserActor::DisplayLines() ...@@ -197,7 +197,6 @@ void AOptiXLaserActor::DisplayLines()
There's no need for 3 huge buffers which contain almost no data, as only a few of the 50 * 50 possible rays get traced. There's no need for 3 huge buffers which contain almost no data, as only a few of the 50 * 50 possible rays get traced.
Really really *really* needs to be refactored to something sensible! Really really *really* needs to be refactored to something sensible!
*/ */
return;
// Update the material here for now TODO // Update the material here for now TODO
// It's definitely not easily possible to have a per-instance color data sadly // It's definitely not easily possible to have a per-instance color data sadly
......
...@@ -17,6 +17,7 @@ AOptiXLaserDetectorActor::AOptiXLaserDetectorActor(const FObjectInitializer& Obj ...@@ -17,6 +17,7 @@ AOptiXLaserDetectorActor::AOptiXLaserDetectorActor(const FObjectInitializer& Obj
UE_LOG(LogTemp, Display, TEXT("OptiX Laser Detector Actor Constructor")); UE_LOG(LogTemp, Display, TEXT("OptiX Laser Detector Actor Constructor"));
PrimaryActorTick.bCanEverTick = false; PrimaryActorTick.bCanEverTick = false;
bIsEnabled = true;
static ConstructorHelpers::FObjectFinder<UStaticMesh>MeshAsset(TEXT("StaticMesh'/OptiX/target.target'")); static ConstructorHelpers::FObjectFinder<UStaticMesh>MeshAsset(TEXT("StaticMesh'/OptiX/target.target'"));
UStaticMesh* Asset = MeshAsset.Object; UStaticMesh* Asset = MeshAsset.Object;
...@@ -68,7 +69,7 @@ void AOptiXLaserDetectorActor::Init() ...@@ -68,7 +69,7 @@ void AOptiXLaserDetectorActor::Init()
int32 Size = static_cast<int32>(OptiXLaserTargetComponent->TargetRes); int32 Size = static_cast<int32>(OptiXLaserTargetComponent->TargetRes);
DetectorResultTexture = UTexture2D::CreateTransient(Size, Size, PF_B8G8R8A8); DetectorResultTexture = UTexture2D::CreateTransient(Size, Size, PF_R32_FLOAT);
//OutputTexture->AddToRoot(); //OutputTexture->AddToRoot();
//// Allocate the texture HRI //// Allocate the texture HRI
DetectorResultTexture->UpdateResource(); DetectorResultTexture->UpdateResource();
...@@ -85,18 +86,39 @@ void AOptiXLaserDetectorActor::Init() ...@@ -85,18 +86,39 @@ void AOptiXLaserDetectorActor::Init()
void AOptiXLaserDetectorActor::OnLaserTraceFinished() void AOptiXLaserDetectorActor::OnLaserTraceFinished()
{ {
OptiXLaserTargetComponent->UpdateBufferData(); if (bIsEnabled)
{
//OptiXLaserTargetComponent->UpdateBufferData();
RenderDataToTarget(); RenderDataToTarget();
} }
}
void AOptiXLaserDetectorActor::RenderDataToTarget() void AOptiXLaserDetectorActor::RenderDataToTarget()
{ {
// Let's try something else:
int32 Size = static_cast<int32>(OptiXLaserTargetComponent->TargetRes); int32 Size = static_cast<int32>(OptiXLaserTargetComponent->TargetRes);
DetectorResultTexture->UpdateTextureRegions(0, 1, TextureRegion.Get(), Size * 4, 4, (uint8*)OptiXLaserTargetComponent->ColorData.GetData());
float Max = OptiXLaserTargetComponent->GetMaxFromBuffer();
float* Data = static_cast<float*>(OptiXLaserTargetComponent->TargetBuffer->MapNative(0, RT_BUFFER_MAP_READ));
DetectorResultTexture->UpdateTextureRegions(0, 1, TextureRegion.Get(), Size * 4, 4, (uint8*)Data);
OptiXLaserTargetComponent->TargetBuffer->Unmap();
if (DynamicScreenMaterial != nullptr) if (DynamicScreenMaterial != nullptr)
{ {
DynamicScreenMaterial->SetTextureParameterValue("Texture", DetectorResultTexture); DynamicScreenMaterial->SetTextureParameterValue("ResultTexture", DetectorResultTexture);
DynamicScreenMaterial->SetScalarParameterValue("ResultMax", Max);
} }
//int32 Size = static_cast<int32>(OptiXLaserTargetComponent->TargetRes);
//DetectorResultTexture->UpdateTextureRegions(0, 1, TextureRegion.Get(), Size * 4, 4, (uint8*)OptiXLaserTargetComponent->ColorData.GetData());
//if (DynamicScreenMaterial != nullptr)
//{
// DynamicScreenMaterial->SetTextureParameterValue("Texture", DetectorResultTexture);
//}
} }
\ No newline at end of file
...@@ -158,6 +158,7 @@ float UOptiXLaserTargetComponent::GetMaxFromBuffer() ...@@ -158,6 +158,7 @@ float UOptiXLaserTargetComponent::GetMaxFromBuffer()
void UOptiXLaserTargetComponent::UpdateBufferData() void UOptiXLaserTargetComponent::UpdateBufferData()
{ {
float Max = GetMaxFromBuffer(); float Max = GetMaxFromBuffer();
UE_LOG(LogTemp, Warning, TEXT("UPDATING DEPRECATED BUFFER DATA"));
float* Data = static_cast<float*>(TargetBuffer->MapNative(0, RT_BUFFER_MAP_READ)); float* Data = static_cast<float*>(TargetBuffer->MapNative(0, RT_BUFFER_MAP_READ));
......
...@@ -2,8 +2,13 @@ ...@@ -2,8 +2,13 @@
#include "OptiXPlayerController.h" #include "OptiXPlayerController.h"
#include "Runtime/Engine/Classes/Kismet/GameplayStatics.h"
#include "OptiXLaserActor.h"
#include "OptiXLaserDetectorActor.h"
#include "OptiXModule.h" #include "OptiXModule.h"
AOptiXPlayerController::AOptiXPlayerController(const FObjectInitializer& ObjectInitializer) AOptiXPlayerController::AOptiXPlayerController(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer) : Super(ObjectInitializer)
{ {
...@@ -33,6 +38,14 @@ void AOptiXPlayerController::EndPlay(const EEndPlayReason::Type EndPlayReason) ...@@ -33,6 +38,14 @@ void AOptiXPlayerController::EndPlay(const EEndPlayReason::Type EndPlayReason)
OptiXPlayerCameraManager = nullptr; OptiXPlayerCameraManager = nullptr;
} }
void AOptiXPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
InputComponent->BindAction("ToggleLaserTrace", IE_Pressed, this, &AOptiXPlayerController::ToggleLaserTrace);
InputComponent->BindAction("ToggleLaserDetector", IE_Pressed, this, &AOptiXPlayerController::ToggleLaserDetector);
}
void AOptiXPlayerController::Tick(float DeltaSeconds) void AOptiXPlayerController::Tick(float DeltaSeconds)
{ {
Super::Tick(DeltaSeconds); Super::Tick(DeltaSeconds);
...@@ -52,3 +65,30 @@ void AOptiXPlayerController::Tick(float DeltaSeconds) ...@@ -52,3 +65,30 @@ void AOptiXPlayerController::Tick(float DeltaSeconds)
} }
void AOptiXPlayerController::ToggleLaserDetector()
{
TArray<AActor*> FoundLaserDetectorActors;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AOptiXLaserDetectorActor::StaticClass(), FoundLaserDetectorActors);
for (AActor* Actor : FoundLaserDetectorActors)
{
bool bNew = !Cast<AOptiXLaserDetectorActor>(Actor)->bIsEnabled;
Cast<AOptiXLaserDetectorActor>(Actor)->bIsEnabled = bNew;
UE_LOG(LogTemp, Warning, TEXT("Set Laser Detector Update to: %i"), static_cast<int32>(bNew));
}
}
void AOptiXPlayerController::ToggleLaserTrace()
{
TArray<AActor*> FoundLaserActors;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AOptiXLaserActor::StaticClass(), FoundLaserActors);
for (AActor* Actor : FoundLaserActors)
{
bool bNew = !Cast<AOptiXLaserActor>(Actor)->bLaserTraceEnabled;
Cast<AOptiXLaserActor>(Actor)->bLaserTraceEnabled = bNew;
UE_LOG(LogTemp, Warning, TEXT("Set Laser Trace Update to: %i"), static_cast<int32>(bNew));
Cast<AOptiXLaserActor>(Actor)->InstancedStaticMeshComponent->SetVisibility(bNew, true);
}
}
...@@ -37,13 +37,17 @@ public: ...@@ -37,13 +37,17 @@ public:
public: public:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = OptiX)
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "OptiX")
bool bIsEnabled;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "OptiX")
UOptiXLaserTargetComponent* OptiXLaserTargetComponent; UOptiXLaserTargetComponent* OptiXLaserTargetComponent;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = OptiX) UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "OptiX")
UTexture2D* DetectorResultTexture; UTexture2D* DetectorResultTexture;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = OptiX) UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "OptiX")
UMaterialInstanceDynamic* DynamicScreenMaterial; UMaterialInstanceDynamic* DynamicScreenMaterial;
TUniquePtr<FUpdateTextureRegion2D> TextureRegion; TUniquePtr<FUpdateTextureRegion2D> TextureRegion;
......
...@@ -29,8 +29,17 @@ public: ...@@ -29,8 +29,17 @@ public:
virtual void BeginPlay() override; virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
virtual void SetupInputComponent() override;
virtual void Tick(float DeltaSeconds) override; virtual void Tick(float DeltaSeconds) override;
UFUNCTION()
void ToggleLaserDetector();
UFUNCTION()
void ToggleLaserTrace();
// APlayerController interface end // APlayerController interface end
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment