diff --git a/Content/Laser/LaserMaterial.uasset b/Content/Laser/LaserMaterial.uasset index 3b9e1a257db445b1203e88822864e4abdec10d6d..47ad26dc3aee9278deced57271f3475bf4cda69f 100644 Binary files a/Content/Laser/LaserMaterial.uasset and b/Content/Laser/LaserMaterial.uasset differ diff --git a/Content/Laser/LoadTexel.uasset b/Content/Laser/LoadTexel.uasset new file mode 100644 index 0000000000000000000000000000000000000000..fe4eb193a6e4b50271c3b9a6362dc0370dbb6389 Binary files /dev/null and b/Content/Laser/LoadTexel.uasset differ diff --git a/Source/OptiX/Private/LineInstancedStaticMeshComponent.cpp b/Source/OptiX/Private/LineInstancedStaticMeshComponent.cpp index dde61225c081e6f86db7d53bbe14c8819a406088..65e8a84d301eccf6a9b8e0e91a23fffccde0aef1 100644 --- a/Source/OptiX/Private/LineInstancedStaticMeshComponent.cpp +++ b/Source/OptiX/Private/LineInstancedStaticMeshComponent.cpp @@ -31,7 +31,8 @@ ULineInstancedStaticMeshComponent::ULineInstancedStaticMeshComponent(const FObje SetRenderCustomDepth(true); SetCastShadow(false); SetCollisionEnabled(ECollisionEnabled::NoCollision); - + SetCullDistance(10000); + SetBoundsScale(1000); // Prevent culling due to usage of worldpositionoffset SegmentsPerLine = 20; LineNumber = 16; @@ -95,8 +96,8 @@ void ULineInstancedStaticMeshComponent::InitLineSegments(TArray<int32> Indices, { FTransform LineTransform; - LineTransform.SetScale3D({ 0, 0, 0 }); - LineTransform.SetLocation({ 0, 0, 0 }); + LineTransform.SetScale3D({ 1, 1, 1 }); + LineTransform.SetLocation(GetComponentLocation()); // Rotation - align z to point towards End: @@ -124,6 +125,12 @@ void ULineInstancedStaticMeshComponent::InitLineSegments(TArray<int32> Indices, TextureRegion->Height = LineNumber; TextureRegion->Width = 1; + IndexMap = UTexture2D::CreateTransient(1, LineNumber); + IndexMap->UpdateResource(); + UE_LOG(LogTemp, Display, TEXT("IndexMap | LineNumber (%i | %i "), IndexMap->GetSizeX(), LineNumber); + IndexMap->UpdateTextureRegions(0, 1, TextureRegion.Get(), sizeof(float), sizeof(float), (uint8*)LaserIndices.GetData()); + DynamicLaserMaterial->SetTextureParameterValue("IndexMap", IndexMap); + } } @@ -137,16 +144,13 @@ void ULineInstancedStaticMeshComponent::UpdateLUT(TArray<FColor> ColorMap) // Store the actual laser index in the alpha component of the LUT - bit hacky but should do the trick for now. - // first column stores the ColorLUT = UTexture2D::CreateTransient(1, LineNumber); - ColorLUT->UpdateResource(); - UE_LOG(LogTemp, Display, TEXT("ColorLUT | LineNumber (%i | %i "), ColorLUT->GetSizeX(), LineNumber); - - ColorLUT->UpdateTextureRegions(0, 1, TextureRegion.Get(), sizeof(FColor), sizeof(FColor), (uint8*)ColorArray.GetData()); + ColorLUT->UpdateTextureRegions(0, 1, TextureRegion.Get(), sizeof(FColor), sizeof(FColor), (uint8*)ColorArray.GetData()); DynamicLaserMaterial->SetTextureParameterValue("LUT", ColorLUT); + UE_LOG(LogTemp, Display, TEXT("#Colors: %i"), ColorArray.Num()); } @@ -155,13 +159,17 @@ void ULineInstancedStaticMeshComponent::UpdateLUT(TArray<FColor> ColorMap) void ULineInstancedStaticMeshComponent::SetLaserMaterial(UMaterialInstanceDynamic * Mat) { // 1 for now, could be #Lines if we want multicolored lines - ColorLUT = UTexture2D::CreateTransient(1, LineNumber); + ColorLUT = UTexture2D::CreateTransient(1, LineNumber, EPixelFormat::PF_R32_FLOAT); ColorLUT->UpdateResource(); + IndexMap = UTexture2D::CreateTransient(1, LineNumber); + IndexMap->UpdateResource(); + DynamicLaserMaterial = Mat; SetMaterial(0, DynamicLaserMaterial); DynamicLaserMaterial->SetTextureParameterValue("LUT", ColorLUT); + DynamicLaserMaterial->SetTextureParameterValue("IndexMap", IndexMap); /*DynamicLaserMaterial->SetScalarParameterValue("Segments", SegmentsPerLine); DynamicLaserMaterial->SetScalarParameterValue("Lines", LineNumber); */ diff --git a/Source/OptiX/Private/OptiXContextManager.cpp b/Source/OptiX/Private/OptiXContextManager.cpp index 3754e7f9599802db3dc345317085bc6020e1ea32..5e93c3d8253c839cb0de8c4d32dcce5ea5920aa4 100644 --- a/Source/OptiX/Private/OptiXContextManager.cpp +++ b/Source/OptiX/Private/OptiXContextManager.cpp @@ -576,7 +576,7 @@ void FOptiXContextManager::InitRendering() // Load the materials RegularMaterial = LoadObject<UMaterial>(GetTransientPackage(), TEXT("Material'/OptiX/PPMaterials/TextureMaterial.TextureMaterial'")); VRMaterial = LoadObject<UMaterial>(GetTransientPackage(), TEXT("Material'/OptiX/PPMaterials/TextureMaterialVR.TextureMaterialVR'")); - LaserMaterial = LoadObject<UMaterial>(GetTransientPackage(), TEXT("Material'/OptiX/LaserMaterialOffset.LaserMaterialOffset'")); + LaserMaterial = LoadObject<UMaterial>(GetTransientPackage(), TEXT("Material'/OptiX/Laser/LaserMaterial.LaserMaterial'")); LaserMaterialDynamic = UMaterialInstanceDynamic::Create(LaserMaterial.Get(), OptiXContext.Get(), "DynamicLaserMaterial"); LaserMaterialDynamic->SetTextureParameterValue("IntersectionTexture", LaserIntersectionTexture.Get()); diff --git a/Source/OptiX/Public/LineInstancedStaticMeshComponent.h b/Source/OptiX/Public/LineInstancedStaticMeshComponent.h index 61df8719750ff756a2b4d40764c52bd6ae59c81d..1c664bf23ed7e5de7552aa84920b361e485fc013 100644 --- a/Source/OptiX/Public/LineInstancedStaticMeshComponent.h +++ b/Source/OptiX/Public/LineInstancedStaticMeshComponent.h @@ -53,6 +53,9 @@ public: UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = OptiX) UTexture2D* ColorLUT; + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = OptiX) + UTexture2D* IndexMap; + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = OptiX) TArray<FColor> ColorArray;