diff --git a/Content/Laser/LaserMaterial.uasset b/Content/Laser/LaserMaterial.uasset index 47ad26dc3aee9278deced57271f3475bf4cda69f..1a4c98e6df2cc1938a2253970c9cb50d76676a44 100644 Binary files a/Content/Laser/LaserMaterial.uasset and b/Content/Laser/LaserMaterial.uasset differ diff --git a/Content/Laser/TransformFromZ.uasset b/Content/Laser/TransformFromZ.uasset new file mode 100644 index 0000000000000000000000000000000000000000..ec19f751c2571d345ee885aec39ccb4a72185ab1 Binary files /dev/null and b/Content/Laser/TransformFromZ.uasset differ diff --git a/Content/LaserOffsetMaterial.uasset b/Content/LaserOffsetMaterial.uasset index e68f40395f82230da3b352a22927aae7592df0f4..6a74a31533028e7976bd3b09a539fbebfaa5feb9 100644 Binary files a/Content/LaserOffsetMaterial.uasset and b/Content/LaserOffsetMaterial.uasset differ diff --git a/Content/UI/Tablet/LaserMenuWidget.uasset b/Content/UI/Tablet/LaserMenuWidget.uasset index 877856e25555bd4b986fc3cef433ba4f4fefb796..e6119f05206341fdd281defc8b6a6ec26526715a 100644 Binary files a/Content/UI/Tablet/LaserMenuWidget.uasset and b/Content/UI/Tablet/LaserMenuWidget.uasset differ diff --git a/Source/OptiX/Private/LineInstancedStaticMeshComponent.cpp b/Source/OptiX/Private/LineInstancedStaticMeshComponent.cpp index 65e8a84d301eccf6a9b8e0e91a23fffccde0aef1..12b0ff14029c133a8f81f6ca3d5f37e30614b174 100644 --- a/Source/OptiX/Private/LineInstancedStaticMeshComponent.cpp +++ b/Source/OptiX/Private/LineInstancedStaticMeshComponent.cpp @@ -125,10 +125,18 @@ void ULineInstancedStaticMeshComponent::InitLineSegments(TArray<int32> Indices, TextureRegion->Height = LineNumber; TextureRegion->Width = 1; - IndexMap = UTexture2D::CreateTransient(1, LineNumber); + LaserIndicesFloat.Empty(); + LaserIndicesFloat.SetNumZeroed(LineNumber); + + for (int32 i = 0; i < LineNumber; i++) + { + LaserIndicesFloat[i] = static_cast<float>(LaserIndices[i]); + } + + IndexMap = UTexture2D::CreateTransient(1, LineNumber, EPixelFormat::PF_R32_FLOAT); 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()); + IndexMap->UpdateTextureRegions(0, 1, TextureRegion.Get(), sizeof(float), sizeof(float), (uint8*)LaserIndicesFloat.GetData()); DynamicLaserMaterial->SetTextureParameterValue("IndexMap", IndexMap); } @@ -162,7 +170,7 @@ void ULineInstancedStaticMeshComponent::SetLaserMaterial(UMaterialInstanceDynami ColorLUT = UTexture2D::CreateTransient(1, LineNumber, EPixelFormat::PF_R32_FLOAT); ColorLUT->UpdateResource(); - IndexMap = UTexture2D::CreateTransient(1, LineNumber); + IndexMap = UTexture2D::CreateTransient(1, LineNumber, EPixelFormat::PF_R32_FLOAT); IndexMap->UpdateResource(); DynamicLaserMaterial = Mat; diff --git a/Source/OptiX/Private/OptiXLaserActor.cpp b/Source/OptiX/Private/OptiXLaserActor.cpp index 3e8797e55a5722b86237b0172d016c42402240e9..f3a16b780590591b8c86894dcdca7413a1f9f8cf 100644 --- a/Source/OptiX/Private/OptiXLaserActor.cpp +++ b/Source/OptiX/Private/OptiXLaserActor.cpp @@ -188,9 +188,15 @@ void AOptiXLaserActor::UpdateLaserPattern(EPatternTypes Pattern) LineInstancedStaticMeshComponent->UpdateLUT(OptiXLaserComponent->LaserIndexColorMap); } - -void AOptiXLaserActor::DisplayLines() +void AOptiXLaserActor::UpdateLaserWidth(float NewWidth) { + OptiXLaserComponent->SetLaserWidth(NewWidth); + LineInstancedStaticMeshComponent->DynamicLaserMaterial->SetScalarParameterValue("Width", NewWidth); +} + + +//void AOptiXLaserActor::DisplayLines() +//{ /* This works and is decently efficient but the actual optix setup is incredibly wasteful and weird. 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. @@ -198,7 +204,7 @@ void AOptiXLaserActor::DisplayLines() */ - LineInstancedStaticMeshComponent->UpdateLines(OptiXLaserComponent->GetLaserWidth()); + //LineInstancedStaticMeshComponent->UpdateLines(OptiXLaserComponent->GetLaserWidth()); // Update the material here for now TODO @@ -310,4 +316,4 @@ void AOptiXLaserActor::DisplayLines() //UE_LOG(LogTemp, Display, TEXT("Lines : %i"), Lines.Num()); //MultiLineActorRef->UpdateMesh(Lines); -} +//} diff --git a/Source/OptiX/Private/OptiXLaserComponent.cpp b/Source/OptiX/Private/OptiXLaserComponent.cpp index 6629a7dc10ff097091c281f32cbb738796ca2f33..3a56c2c008f2920e748b8adcaa0381ab2c9f1a28 100644 --- a/Source/OptiX/Private/OptiXLaserComponent.cpp +++ b/Source/OptiX/Private/OptiXLaserComponent.cpp @@ -30,7 +30,7 @@ UOptiXLaserComponent::UOptiXLaserComponent() TargetColorMode = 0; // todo Wavelength = 450.0f; LaserWidth = 0.025f; - CurrentLaserPattern = EPatternTypes::CIRCLE; + CurrentLaserPattern = EPatternTypes::POINTER; LaserTracesPerFrame = 20; // Find and load default patterns: @@ -170,6 +170,7 @@ void UOptiXLaserComponent::UpdateOptiXContextVariables() OptiXContext->SetFloat("laserBeamWidth", LaserWidth); + // Upload buffer data if (bPatternChanged) diff --git a/Source/OptiX/Private/cuda/already generated - optical bench/laser_caster.cu b/Source/OptiX/Private/cuda/already generated - optical bench/laser_caster.cu index d46d488c5089d32e61f0f2a61dc2861686865d79..36fe02f4a3444fe9b9933ecdb0644039a72bbeb4 100644 --- a/Source/OptiX/Private/cuda/already generated - optical bench/laser_caster.cu +++ b/Source/OptiX/Private/cuda/already generated - optical bench/laser_caster.cu @@ -51,7 +51,7 @@ rtDeclareVariable(float, laserSize, , ); rtBuffer<int, 2> laserIndex; rtBuffer<float3, 2> laserDir; -rtBuffer<float4, 1> result_laser; +rtBuffer<float4, 2> result_laser; RT_PROGRAM void laser_caster(){ @@ -80,19 +80,21 @@ RT_PROGRAM void laser_caster(){ Matrix3x3 laser_rot3x3 = make_matrix3x3(laser_rot); - prd.direction = laser_rot3x3 * normalize(make_float3(1,1,-1)*laserDir[make_uint2(launch_index)]); - - unsigned int startIndex = (launch_index.y * 50 + launch_index.x) * max_depth_laser * 2; + prd.direction = laser_rot3x3 * normalize(make_float3(1,1,-1)*laserDir[make_uint2(launch_index)]); + + + unsigned int widthIndex = launch_index.y * 50 + launch_index.x; + //unsigned int startIndex = widthIndex * max_depth_laser * 2; bool cast_ray = laserIndex[make_uint2(launch_index)] < 0; for(int i = 0; i < max_depth_laser * 2; i += 2){ //Determine if this launch_index, depth or last ray should trigger new cast if(cast_ray || prd.done || prd.depth >= max_depth_laser){ // just write rest of data as "invalid" - if(launch_index.z == 0) result_laser[startIndex + i] = make_float4(0,-1,0,1); - if(launch_index.z == 0) result_laser[startIndex + i + 1] = make_float4(0,-1,0,1); + if(launch_index.z == 0) result_laser[make_uint2(widthIndex, i)] = make_float4(0,-1,0,1); + if(launch_index.z == 0) result_laser[make_uint2(widthIndex, i + 1)] = make_float4(0,-1,0,1); continue; } - if(launch_index.z == 0) result_laser[startIndex + i] = make_float4(prd.origin,1); + if(launch_index.z == 0) result_laser[make_uint2(widthIndex, i)] = make_float4(prd.origin,1); ray.origin = prd.origin; ray.direction = prd.direction; @@ -100,6 +102,6 @@ RT_PROGRAM void laser_caster(){ // Update ray data for the next path segment prd.depth++; - if(launch_index.z == 0) result_laser[startIndex + i + 1] = make_float4(prd.origin,1); + if(launch_index.z == 0) result_laser[make_uint2(widthIndex, i + 1)] = make_float4(prd.origin,1); } } \ No newline at end of file diff --git a/Source/OptiX/Private/cuda/miss.cu b/Source/OptiX/Private/cuda/miss.cu new file mode 100644 index 0000000000000000000000000000000000000000..6cc7415f2f0dd6e19d2af3f546974549241a496f --- /dev/null +++ b/Source/OptiX/Private/cuda/miss.cu @@ -0,0 +1,33 @@ +//------------------------------------------------------------------------------ +// Project Phoenix +// +// Copyright (c) 2017-2018 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualization Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the 3-Clause BSD License (the "License"); +// you may not use this file except in compliance with the License. +// See the file LICENSE for the full text. +// You may obtain a copy of the License at +// +// https://opensource.org/licenses/BSD-3-Clause +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include <optix_world.h> +#include "prd.h" + +rtDeclareVariable(PerRayData_radiance_iterative, prd_radiance_it, rtPayload, ); +rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); + +RT_PROGRAM void miss_iterative() +{ + prd_radiance_it.origin = ray.origin + ray.direction * 1500.0f; + prd_radiance_it.done = true; +} diff --git a/Source/OptiX/Public/LineInstancedStaticMeshComponent.h b/Source/OptiX/Public/LineInstancedStaticMeshComponent.h index 1c664bf23ed7e5de7552aa84920b361e485fc013..72fe7f3a2253f3f1c056dfd236e77848597816b6 100644 --- a/Source/OptiX/Public/LineInstancedStaticMeshComponent.h +++ b/Source/OptiX/Public/LineInstancedStaticMeshComponent.h @@ -61,6 +61,7 @@ public: //UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = OptiX) TArray<int32> LaserIndices; + TArray<float> LaserIndicesFloat; TUniquePtr<FUpdateTextureRegion2D> TextureRegion; diff --git a/Source/OptiX/Public/OptiXLaserActor.h b/Source/OptiX/Public/OptiXLaserActor.h index 8315088ffb8ec14454e17948c247e3a9f339d9d7..152342803906d6a1074c9cf3adab658681dbb7b2 100644 --- a/Source/OptiX/Public/OptiXLaserActor.h +++ b/Source/OptiX/Public/OptiXLaserActor.h @@ -34,8 +34,8 @@ public: virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; virtual void Tick(float DeltaTime) override; - UFUNCTION(BlueprintCallable, /*meta = (BlueprintProtected)*/ Category = "OptiXActor") - void DisplayLines(); + //UFUNCTION(BlueprintCallable, /*meta = (BlueprintProtected)*/ Category = "OptiXActor") + //void DisplayLines(); UFUNCTION(BlueprintCallable, /*meta = (BlueprintProtected)*/ Category = "OptiXActor") void UpdateLaserPattern(EPatternTypes Pattern); @@ -48,6 +48,9 @@ public: LineInstancedStaticMeshComponent->SetLaserMaterial(DynamicLaserMaterial); } + UFUNCTION(BlueprintCallable, /*meta = (BlueprintProtected)*/ Category = "OptiXActor") + void UpdateLaserWidth(float NewWidth); + public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = OptiX)