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

Added flexible glass definition support.

Definitions get loaded via a json file.
parent ca2a3bbe
No related branches found
No related tags found
No related merge requests found
[
{
"Name": "BK7",
"B1": 1.03961212,
"B2": 0.231792344,
"B3": 1.01046945,
"C1": 0.00600069867,
"C2": 0.0200179144,
"C3": 103.560653
},
{
"Name": "SF5",
"B1": 1.52481889,
"B2": 0.187085527,
"B3": 1.42729015,
"C1": 0.011254756,
"C2": 0.0588995392,
"C3": 129.141675
},
{
"Name": "SF11",
"B1": 1.73759695,
"B2": 0.313747346,
"B3": 1.89878101,
"C1": 0.013188707,
"C2": 0.0623068142,
"C3": 155.23629
},
{
"Name": "FS",
"B1": 0.6961663,
"B2": 0.4079426,
"B3": 0.8974794,
"C1": 0.0684043,
"C2": 0.1162414,
"C3": 9.896161
},
{
"Name": "SK16",
"B1": 1.34317774,
"B2": 0.241144399,
"B3": 0.994317969,
"C1": 0.00704687339,
"C2": 0.0229005,
"C3": 92.7508526
},
{
"Name": "F2",
"B1": 1.34533359,
"B2": 0.209073176,
"B3": 0.937357162,
"C1": 0.00997743871,
"C2": 0.0470450767,
"C3": 111.886764
}
]
\ No newline at end of file
No preview for this file type
...@@ -60,9 +60,9 @@ public class OptiX : ModuleRules ...@@ -60,9 +60,9 @@ public class OptiX : ModuleRules
"OptiXLibrary", "OptiXLibrary",
"Engine", "Engine",
"HeadMountedDisplay", "HeadMountedDisplay",
"MultiLine" "MultiLine",
//"UnrealEd", "Json",
"JsonUtilities"
} }
); );
......
...@@ -18,6 +18,14 @@ UOptiXLensComponent::UOptiXLensComponent(const FObjectInitializer& ObjectInitial ...@@ -18,6 +18,14 @@ UOptiXLensComponent::UOptiXLensComponent(const FObjectInitializer& ObjectInitial
LensType2 = ELensSideType::CONVEX; LensType2 = ELensSideType::CONVEX;
LensThickness = 0.025 * 100; LensThickness = 0.025 * 100;
CurrentWavelength = 450.0f; CurrentWavelength = 450.0f;
// A little hacky but w/e
for (const TPair<FString, FGlassDefinition>& Pair : FOptiXModule::Get().GetGlassDefinitions())
{
GlassType = Pair.Key;
break;
}
} }
void UOptiXLensComponent::UpdateOptiXComponentVariables() void UOptiXLensComponent::UpdateOptiXComponentVariables()
...@@ -45,7 +53,7 @@ void UOptiXLensComponent::UpdateOptiXComponentVariables() ...@@ -45,7 +53,7 @@ void UOptiXLensComponent::UpdateOptiXComponentVariables()
double WL2 = FMath::Pow(CurrentWavelength / 1000.0, 2.0f); double WL2 = FMath::Pow(CurrentWavelength / 1000.0, 2.0f);
GlassDefinition Def = GlassDefinitions[static_cast<uint8>(GlassType)]; FGlassDefinition Def = FOptiXModule::Get().GetGlassDefinitions()[GlassType];
//UE_LOG(LogTemp, Display, TEXT("Glass Def: %f, %f, %F"), Def.B.X, Def.B.Y, Def.B.Z); //UE_LOG(LogTemp, Display, TEXT("Glass Def: %f, %f, %F"), Def.B.X, Def.B.Y, Def.B.Z);
float Index = FMath::Sqrt(1 + float Index = FMath::Sqrt(1 +
...@@ -310,16 +318,16 @@ ELensSideType UOptiXLensComponent::GetLensType2() const ...@@ -310,16 +318,16 @@ ELensSideType UOptiXLensComponent::GetLensType2() const
return LensType2; return LensType2;
} }
void UOptiXLensComponent::SetGlassType(EGlassType Type) void UOptiXLensComponent::SetGlassType(FString Type)
{ {
UE_LOG(LogTemp, Display, TEXT("Setting Glass Type: %i"), static_cast<int>(Type)); UE_LOG(LogTemp, Display, TEXT("Setting Glass Type: %s"), *Type);
GlassType = Type; GlassType = Type;
SetWavelength(CurrentWavelength); // ??? SetWavelength(CurrentWavelength); // ???
QueueOptiXContextUpdate(); QueueOptiXContextUpdate();
} }
EGlassType UOptiXLensComponent::GetGlassType() const FString UOptiXLensComponent::GetGlassType() const
{ {
return GlassType; return GlassType;
} }
...@@ -417,3 +425,15 @@ void UOptiXLensComponent::RecalculateBoundingBox() ...@@ -417,3 +425,15 @@ void UOptiXLensComponent::RecalculateBoundingBox()
// TODO // TODO
} }
TArray<FString> UOptiXLensComponent::GetGlassDefinitionNames()
{
TArray<FString> Names;
for (const TPair<FString, FGlassDefinition>& Pair : FOptiXModule::Get().GetGlassDefinitions())
{
Names.Add(Pair.Key);
}
return Names;
}
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
#include "Interfaces/IPluginManager.h" #include "Interfaces/IPluginManager.h"
#include <Runtime/Engine/Classes/Engine/Engine.h> #include <Runtime/Engine/Classes/Engine/Engine.h>
#include "Json.h"
#include "JsonObjectConverter.h"
#include "OptiXContextManager.h" #include "OptiXContextManager.h"
...@@ -49,6 +50,8 @@ void FOptiXModule::StartupModule() ...@@ -49,6 +50,8 @@ void FOptiXModule::StartupModule()
LoadDLLs(); LoadDLLs();
Singleton = this; Singleton = this;
LoadGlassDefinitions();
// Set optix compiled shader path // Set optix compiled shader path
OptiXPTXDir = FPaths::ProjectContentDir() / TEXT("ptx/"); OptiXPTXDir = FPaths::ProjectContentDir() / TEXT("ptx/");
} }
...@@ -110,6 +113,23 @@ void FOptiXModule::UnloadDLLs() ...@@ -110,6 +113,23 @@ void FOptiXModule::UnloadDLLs()
FPlatformProcess::FreeDllHandle(OptixUHandle); FPlatformProcess::FreeDllHandle(OptixUHandle);
} }
void FOptiXModule::LoadGlassDefinitions()
{
FString JsonString;
FString Path = IPluginManager::Get().FindPlugin(TEXT("OptiX"))->GetContentDir().Append("/GlassDefinitions/GlassDefinitions.json");
FFileHelper::LoadFileToString(JsonString, *Path);
TArray<FRawGlassDefinition> Array;
FJsonObjectConverter::JsonArrayStringToUStruct<FRawGlassDefinition>(JsonString, &Array, 0, 0);
for (const FRawGlassDefinition& Def : Array)
{
GlassDefinitionsMap.Emplace(Def.Name, FGlassDefinition(FVector(Def.B1, Def.B2, Def.B3), FVector(Def.C1, Def.C2, Def.C3)));
}
}
// Init the context manager. This is called from the game thread in initgame, NOT on module startup. // Init the context manager. This is called from the game thread in initgame, NOT on module startup.
void FOptiXModule::Init() void FOptiXModule::Init()
{ {
......
#pragma once
#include "CoreMinimal.h"
#include "OptiXGlassDefinitions.generated.h"
// Okay, for some crazy reason glass definitions have been originally saved here... TODOOOOO
USTRUCT(BlueprintType)
struct FGlassDefinition
{
GENERATED_BODY()
UPROPERTY(BlueprintReadOnly)
FVector B;
UPROPERTY(BlueprintReadOnly)
FVector C;
FGlassDefinition(FVector b, FVector c) : B(b), C(c)
{}
FGlassDefinition() {}
};
USTRUCT()
struct FRawGlassDefinition
{
GENERATED_BODY()
UPROPERTY()
FString Name;
UPROPERTY()
float B1;
UPROPERTY()
float B2;
UPROPERTY()
float B3;
UPROPERTY()
float C1;
UPROPERTY()
float C2;
UPROPERTY()
float C3;
};
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "OptiXObjectComponent.h" #include "OptiXObjectComponent.h"
#include "OptiXGlassDefinitions.h"
#include "OptiXLensComponent.generated.h" #include "OptiXLensComponent.generated.h"
/** /**
...@@ -17,19 +19,19 @@ enum class ELensSideType : uint8 // Unreal seems to only support uint8 for bluep ...@@ -17,19 +19,19 @@ enum class ELensSideType : uint8 // Unreal seems to only support uint8 for bluep
CONCAVE = 2 UMETA(DisplayName = "Concave") CONCAVE = 2 UMETA(DisplayName = "Concave")
}; };
/** ///**
* Glass Type Enum // * Glass Type Enum
*/ // */
UENUM(BlueprintType) //UENUM(BlueprintType)
enum class EGlassType : uint8 // TODO fix descriptions //enum class EGlassType : uint8 // TODO fix descriptions
{ //{
BK7 = 0 UMETA(DisplayName = "BK7"), // BK7 = 0 UMETA(DisplayName = "BK7"),
SF5 = 1 UMETA(DisplayName = "SF5"), // SF5 = 1 UMETA(DisplayName = "SF5"),
SF11 = 2 UMETA(DisplayName = "SF11"), // SF11 = 2 UMETA(DisplayName = "SF11"),
FUSED_SILICA = 3 UMETA(DisplayName = "Fused silicia"), // FUSED_SILICA = 3 UMETA(DisplayName = "Fused silicia"),
SK16 = 4 UMETA(DisplayName = "SK16"), // SK16 = 4 UMETA(DisplayName = "SK16"),
F2 = 5 UMETA(DisplayName = "F2") // F2 = 5 UMETA(DisplayName = "F2")
}; //};
/** /**
* Lens Component * Lens Component
...@@ -101,9 +103,10 @@ public: ...@@ -101,9 +103,10 @@ public:
ELensSideType GetLensType2() const; ELensSideType GetLensType2() const;
UFUNCTION(BlueprintCallable, /*meta = (BlueprintProtected)*/ Category = "OptiXLensComponent") UFUNCTION(BlueprintCallable, /*meta = (BlueprintProtected)*/ Category = "OptiXLensComponent")
void SetGlassType(EGlassType Type); void SetGlassType(FString Type);
UFUNCTION(BlueprintPure, BlueprintCallable, /*meta = (BlueprintProtected)*/ Category = "OptiXLensComponent") UFUNCTION(BlueprintPure, BlueprintCallable, /*meta = (BlueprintProtected)*/ Category = "OptiXLensComponent")
EGlassType GetGlassType() const; FString GetGlassType() const;
UFUNCTION(BlueprintCallable, /*meta = (BlueprintProtected)*/ Category = "OptiXLensComponent") UFUNCTION(BlueprintCallable, /*meta = (BlueprintProtected)*/ Category = "OptiXLensComponent")
void SetWavelength(float WL); void SetWavelength(float WL);
...@@ -113,6 +116,8 @@ public: ...@@ -113,6 +116,8 @@ public:
UFUNCTION(BlueprintCallable, /*meta = (BlueprintProtected)*/ Category = "OptiXLensComponent") // TODO UFUNCTION(BlueprintCallable, /*meta = (BlueprintProtected)*/ Category = "OptiXLensComponent") // TODO
void MarkDirty(); void MarkDirty();
UFUNCTION(BlueprintCallable, /*meta = (BlueprintProtected)*/ Category = "OptiXLensComponent") // TODO
TArray<FString> GetGlassDefinitionNames();
public: public:
...@@ -139,7 +144,7 @@ public: ...@@ -139,7 +144,7 @@ public:
ELensSideType LensType2; // todo fix names again gah ELensSideType LensType2; // todo fix names again gah
UPROPERTY(BlueprintReadWrite, EditAnywhere, BlueprintGetter=GetGlassType, BlueprintSetter=SetGlassType) UPROPERTY(BlueprintReadWrite, EditAnywhere, BlueprintGetter=GetGlassType, BlueprintSetter=SetGlassType)
EGlassType GlassType; FString GlassType;
// Wavelength in NM // Wavelength in NM
UPROPERTY(BlueprintReadWrite, EditAnywhere, BlueprintGetter=GetWavelength, BlueprintSetter=SetWavelength) UPROPERTY(BlueprintReadWrite, EditAnywhere, BlueprintGetter=GetWavelength, BlueprintSetter=SetWavelength)
...@@ -171,21 +176,21 @@ private: ...@@ -171,21 +176,21 @@ private:
// Okay, for some crazy reason glass definitions have been originally saved here... TODOOOOO // Okay, for some crazy reason glass definitions have been originally saved here... TODOOOOO
struct GlassDefinition //struct GlassDefinition
{ //{
FVector B; // FVector B;
FVector C; // FVector C;
GlassDefinition(FVector b, FVector c) : B(b), C(c) // GlassDefinition(FVector b, FVector c) : B(b), C(c)
{} // {}
}; //};
const TArray<GlassDefinition> GlassDefinitions = //const TArray<GlassDefinition> GlassDefinitions =
{ //{
GlassDefinition(FVector(1.03961212f, 0.231792344f, 1.01046945f), FVector(0.00600069867f, 0.0200179144f, 103.560653f)), // BK7 // GlassDefinition(FVector(1.03961212f, 0.231792344f, 1.01046945f), FVector(0.00600069867f, 0.0200179144f, 103.560653f)), // BK7
GlassDefinition(FVector(1.52481889f, 0.187085527f, 1.42729015f), FVector(0.011254756f, 0.0588995392f, 129.141675f)), // SF5 // GlassDefinition(FVector(1.52481889f, 0.187085527f, 1.42729015f), FVector(0.011254756f, 0.0588995392f, 129.141675f)), // SF5
GlassDefinition(FVector(1.73759695f, 0.313747346f, 1.89878101f), FVector(0.013188707f, 0.0623068142f, 155.23629f)), // SF11 // GlassDefinition(FVector(1.73759695f, 0.313747346f, 1.89878101f), FVector(0.013188707f, 0.0623068142f, 155.23629f)), // SF11
GlassDefinition(FVector(0.6961663f, 0.4079426f, 0.8974794f), FVector(0.0684043f, 0.1162414f, 9.896161f)), // Fused S. // GlassDefinition(FVector(0.6961663f, 0.4079426f, 0.8974794f), FVector(0.0684043f, 0.1162414f, 9.896161f)), // Fused S.
GlassDefinition(FVector(1.34317774f, 0.241144399f, 0.994317969f), FVector(0.00704687339f, 0.0229005f, 92.7508526f)), // SK16 // GlassDefinition(FVector(1.34317774f, 0.241144399f, 0.994317969f), FVector(0.00704687339f, 0.0229005f, 92.7508526f)), // SK16
GlassDefinition(FVector(1.34533359f, 0.209073176f, 0.937357162f), FVector(0.00997743871f, 0.0470450767f, 111.886764f)), // F2 // GlassDefinition(FVector(1.34533359f, 0.209073176f, 0.937357162f), FVector(0.00997743871f, 0.0470450767f, 111.886764f)), // F2
}; //};
}; };
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include "Modules/ModuleInterface.h" #include "Modules/ModuleInterface.h"
#include "OptiXContextManager.h" #include "OptiXContextManager.h"
#include "OptiXGlassDefinitions.h"
DECLARE_LOG_CATEGORY_EXTERN(OptiXPlugin, Log, All); DECLARE_LOG_CATEGORY_EXTERN(OptiXPlugin, Log, All);
...@@ -38,6 +40,11 @@ public: ...@@ -38,6 +40,11 @@ public:
return GetOptiXContextManager()->GetOptiXContext(); return GetOptiXContextManager()->GetOptiXContext();
} }
TMap<FString, FGlassDefinition>& GetGlassDefinitions()
{
return GlassDefinitionsMap;
}
public: public:
FString OptiXPTXDir; FString OptiXPTXDir;
...@@ -52,6 +59,8 @@ private: ...@@ -52,6 +59,8 @@ private:
void LoadDLLs(); void LoadDLLs();
void UnloadDLLs(); void UnloadDLLs();
void LoadGlassDefinitions();
void* CudaRtHandle; void* CudaRtHandle;
void* OptixHandle; void* OptixHandle;
void* OptixUHandle; void* OptixUHandle;
...@@ -59,5 +68,7 @@ private: ...@@ -59,5 +68,7 @@ private:
// Pointer probably doesn't need to be thread safe in this case, check this // Pointer probably doesn't need to be thread safe in this case, check this
TSharedPtr<FOptiXContextManager, ESPMode::ThreadSafe> OptiXContextManager; TSharedPtr<FOptiXContextManager, ESPMode::ThreadSafe> OptiXContextManager;
TMap<FString, FGlassDefinition> GlassDefinitionsMap;
static FOptiXModule* Singleton; static FOptiXModule* Singleton;
}; };
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment