diff --git a/Content/Blueprints/OptiXObjects/OptiXLaserActor_Pickup.uasset b/Content/Blueprints/OptiXObjects/OptiXLaserActor_Pickup.uasset index 5118f50de56a22e50f77d906280de1a373da582e..6d40cd17d5dae623dc4034a80625c98f01ede68a 100644 Binary files a/Content/Blueprints/OptiXObjects/OptiXLaserActor_Pickup.uasset and b/Content/Blueprints/OptiXObjects/OptiXLaserActor_Pickup.uasset differ diff --git a/Content/Laser/Cylinder.uasset b/Content/Laser/Cylinder.uasset index 9e4449ba94404a0a7db5d8bac9db548c9927f4ac..86a1542feb02b1e68266f337af10575c0e0e4c9c 100644 Binary files a/Content/Laser/Cylinder.uasset and b/Content/Laser/Cylinder.uasset differ diff --git a/Content/Laser/LaserMaterial.uasset b/Content/Laser/LaserMaterial.uasset index 8121da9f89ca61ef86b71803a362b1c6342e5b26..36151c00cf6df9fbd49fb83b5f86809aefd5f1fb 100644 Binary files a/Content/Laser/LaserMaterial.uasset and b/Content/Laser/LaserMaterial.uasset differ diff --git a/Source/OptiX/Private/LineInstancedStaticMeshComponent.cpp b/Source/OptiX/Private/LineInstancedStaticMeshComponent.cpp index f33e21d6f460b34dc039cf8dc043c47169d1d390..f3a921b1d8e69346291ca093dfd8c7fe6f2adbf4 100644 --- a/Source/OptiX/Private/LineInstancedStaticMeshComponent.cpp +++ b/Source/OptiX/Private/LineInstancedStaticMeshComponent.cpp @@ -31,8 +31,8 @@ ULineInstancedStaticMeshComponent::ULineInstancedStaticMeshComponent(const FObje SetRenderCustomDepth(true); SetCastShadow(false); SetCollisionEnabled(ECollisionEnabled::NoCollision); - SetCullDistance(10000); - SetBoundsScale(1000); // Prevent culling due to usage of worldpositionoffset + //SetCullDistance(10000); + //SetBoundsScale(1000); // Prevent culling due to usage of worldpositionoffset SegmentsPerLine = 20; LineNumber = 16; @@ -47,6 +47,7 @@ void ULineInstancedStaticMeshComponent::BeginPlay() FPrimitiveSceneProxy* ULineInstancedStaticMeshComponent::CreateSceneProxy() { + FPrimitiveSceneProxy* Proxy = Super::CreateSceneProxy(); if (!PerInstanceRenderData.IsValid() || PerInstanceSMData.Num() < 1 ) @@ -63,20 +64,15 @@ FPrimitiveSceneProxy* ULineInstancedStaticMeshComponent::CreateSceneProxy() for (int32 Index = 0; Index < NumInstancesRenderData; ++Index) { - int32 RenderIndex = InstanceReorderTable.IsValidIndex(Index) ? InstanceReorderTable[Index] : Index; - if (RenderIndex == INDEX_NONE) - { - // could be skipped by density settings - continue; - } + //int32 RenderIndex = InstanceReorderTable.IsValidIndex(Index) ? InstanceReorderTable[Index] : Index; FMatrix Transform; PerInstanceRenderData->InstanceBuffer_GameThread->GetInstanceTransform(Index, Transform); - float Id = static_cast<float>(Index) + 0.5f; - PerInstanceRenderData->InstanceBuffer_GameThread->SetInstance(Index, Transform, 0.0f); - UE_LOG(LogTemp, Display, TEXT("%f"), Id); - FFloat16 half = FFloat16(Id); - UE_LOG(LogTemp, Display, TEXT("Half: %f"), half.GetFloat()); + //float Id = static_cast<float>(Index) + 0.5f; + PerInstanceRenderData->InstanceBuffer_GameThread->SetInstance(Index, Transform, Index + 0.5f); + //UE_LOG(LogTemp, Display, TEXT("%f"), RenderIndex + 0.5f); + //FFloat16 half = FFloat16(Id); + //UE_LOG(LogTemp, Display, TEXT("Half: %f"), half.GetFloat()); } @@ -115,7 +111,9 @@ void ULineInstancedStaticMeshComponent::InitLineSegments(TArray<int32> Indices, } int32 Index = AddInstanceWorldSpace(LineTransform); - UE_LOG(LogTemp, Display, TEXT("Line Instance Index: %i"), Index); + //UE_LOG(LogTemp, Display, TEXT("Line Instance Index: %i"), Index); + //UpdateInstanceTransform(Index, LineTransform, true, true, false); + } } @@ -146,6 +144,34 @@ void ULineInstancedStaticMeshComponent::InitLineSegments(TArray<int32> Indices, DynamicLaserMaterial->SetTextureParameterValue("IndexMap", IndexMap); } + + UpdateLines(); +} + +void ULineInstancedStaticMeshComponent::UpdateLines() +{ + LineNumber = LaserIndices.Num(); + + for (int32 Line = 0; Line < LineNumber; Line++) + { + for (int32 Segment = 0; Segment < SegmentsPerLine; Segment++) + { + FTransform LineTransform; + + LineTransform.SetScale3D({ 1, 1, 1 }); + LineTransform.SetLocation(GetComponentLocation()); + + LineTransform.SetRotation(FQuat::Identity); + + if (LineTransform.ContainsNaN()) + { + UE_LOG(LogTemp, Fatal, TEXT("Line Transform contains NaNs!")); + } + + UpdateInstanceTransform(Line * Segment, LineTransform, true, true, false); + + } + } } void ULineInstancedStaticMeshComponent::UpdateLUT(TArray<FColor> ColorMap) diff --git a/Source/OptiX/Private/OptiXContextManager.cpp b/Source/OptiX/Private/OptiXContextManager.cpp index 5e93c3d8253c839cb0de8c4d32dcce5ea5920aa4..4880f361656d8e01476548c09ba5040a9dfb4ecd 100644 --- a/Source/OptiX/Private/OptiXContextManager.cpp +++ b/Source/OptiX/Private/OptiXContextManager.cpp @@ -24,6 +24,8 @@ #include "Runtime/Engine/Classes/GameFramework/GameUserSettings.h" +#include "Async.h" + // Console variables todo static TAutoConsoleVariable<int32> CVarDisableTrace( @@ -276,7 +278,16 @@ void FOptiXContextManager::LaunchLaser() { if (LaserActor.IsValid()) { + //bool bQueueTransformUpdate = LaserActor->OptiXLaserComponent->bPatternChanged; LaserActor->OptiXLaserComponent->UpdateOptiXContextVariables(); + //LaserActor->LineInstancedStaticMeshComponent->UpdateLines(); + //if (bQueueTransformUpdate) + //{ + // AsyncTask(ENamedThreads::GameThread, [Laser = LaserActor.Get()]() { + // Laser->LineInstancedStaticMeshComponent->UpdateLines(); + // } + // ); + //} } // uuuuuuuuh diff --git a/Source/OptiX/Private/OptiXLaserActor.cpp b/Source/OptiX/Private/OptiXLaserActor.cpp index f3a16b780590591b8c86894dcdca7413a1f9f8cf..93b7d4b8211191b431731a72b4a36b99cf9e04a6 100644 --- a/Source/OptiX/Private/OptiXLaserActor.cpp +++ b/Source/OptiX/Private/OptiXLaserActor.cpp @@ -100,6 +100,8 @@ void AOptiXLaserActor::Tick(float DeltaTime) // We don't need to trace each tick, but only if either the optix scene changed, or the laser position moved. Super::Tick(DeltaTime); + //LineInstancedStaticMeshComponent->UpdateLines(); + //if (bLaserTraceEnabled) //{ // // Check if there's anything in the queue @@ -179,8 +181,9 @@ void AOptiXLaserActor::UpdateLaserPattern(EPatternTypes Pattern) MultiLineActorRef->GetMeshComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);*/ - OptiXLaserComponent->SetLaserPattern(Pattern); + OptiXLaserComponent->PreparePatternChange(Pattern); LineInstancedStaticMeshComponent->InitLineSegments(OptiXLaserComponent->LaserIndices, 20); + OptiXLaserComponent->SetLaserPattern(Pattern); UE_LOG(LogTemp, Display, TEXT("#Colors: %i"), OptiXLaserComponent->LaserIndexColorMap.Num()); diff --git a/Source/OptiX/Private/OptiXLaserComponent.cpp b/Source/OptiX/Private/OptiXLaserComponent.cpp index 3a56c2c008f2920e748b8adcaa0381ab2c9f1a28..26634f505be50644b0356fac8dd5794e14a6a024 100644 --- a/Source/OptiX/Private/OptiXLaserComponent.cpp +++ b/Source/OptiX/Private/OptiXLaserComponent.cpp @@ -394,27 +394,33 @@ void UOptiXLaserComponent::SetLaserPattern(EPatternTypes Pattern) number of rays and their index here, so we don't have to copy and draw the whole result buffer. */ - UE_LOG(LogTemp, Display, TEXT("OptiX Laser Component Changing Laser Pattern")); + UE_LOG(LogTemp, Display, TEXT("OptiX Laser Component Queuing Laser Pattern Change")); CurrentLaserPattern = Pattern; - bUpdateQueued.AtomicSet(true); - bPatternChanged.AtomicSet(true); // Update the base indices first so that the game thread can directly create the insanced lines instead of having to wait for the render thread // The actual positions will get updated when the render thread catches up. + + bUpdateQueued.AtomicSet(true); + bPatternChanged.AtomicSet(true); +} - if (Patterns[CurrentLaserPattern]->PlatformData->Mips.Num() != 0) +void UOptiXLaserComponent::PreparePatternChange(EPatternTypes Pattern) +{ + UE_LOG(LogTemp, Display, TEXT("OptiX Laser Component Preparing Laser Pattern Change")); + + if (Patterns[Pattern]->PlatformData->Mips.Num() != 0) { LaserIndices.Empty(); LaserIndexColorMap.Empty(); - FTexture2DMipMap& IndexMip = Patterns[CurrentLaserPattern]->PlatformData->Mips[0]; + FTexture2DMipMap& IndexMip = Patterns[Pattern]->PlatformData->Mips[0]; UE_LOG(LogTemp, Display, TEXT("Got Texture mips")); FColor* TextureData = static_cast<FColor*>(IndexMip.BulkData.Lock(LOCK_READ_WRITE)); - int X = Patterns[CurrentLaserPattern]->GetSizeX(); - int Y = Patterns[CurrentLaserPattern]->GetSizeY(); + int X = Patterns[Pattern]->GetSizeX(); + int Y = Patterns[Pattern]->GetSizeY(); for (int32 i = 0; i < X; ++i) { for (int32 j = 0; j < Y; ++j) { diff --git a/Source/OptiX/Public/LineInstancedStaticMeshComponent.h b/Source/OptiX/Public/LineInstancedStaticMeshComponent.h index 9e53e5cdec6ae5cc31855ddb3218b225183e4d00..3321d88387be302964623f134ac4adc2aa2debb0 100644 --- a/Source/OptiX/Public/LineInstancedStaticMeshComponent.h +++ b/Source/OptiX/Public/LineInstancedStaticMeshComponent.h @@ -30,7 +30,7 @@ public: void InitLineSegments(TArray<int32> LaserIndices, int32 NumberOfSegmentsPerLine, float LineW = 0.01); - //void UpdateLines(float NewLineWidth); + void UpdateLines(); void UpdateLUT(TArray<FColor> ColorMap); diff --git a/Source/OptiX/Public/OptiXLaserComponent.h b/Source/OptiX/Public/OptiXLaserComponent.h index fda6964c7b962e487ebd9527a263affa867617f0..c8a4306927a6124bffd24b83e399f328e1e4935e 100644 --- a/Source/OptiX/Public/OptiXLaserComponent.h +++ b/Source/OptiX/Public/OptiXLaserComponent.h @@ -92,6 +92,9 @@ public: UFUNCTION(BlueprintCallable, /*meta = (BlueprintProtected)*/ Category = "OptiXLaserComponent") void SetLaserPattern(EPatternTypes Pattern); + UFUNCTION(BlueprintCallable, /*meta = (BlueprintProtected)*/ Category = "OptiXLaserComponent") + void PreparePatternChange(EPatternTypes Pattern); + UFUNCTION(BlueprintPure, BlueprintCallable, /*meta = (BlueprintProtected)*/ Category = "OptiXLaserComponent") EPatternTypes GetLaserPattern() const;