Something went wrong on our end
Select Git revision
OptiXLensComponent.cpp
-
David Gilbert authored
- wavelength change now gets broadcast to lenses correctly
David Gilbert authored- wavelength change now gets broadcast to lenses correctly
OptiXLensComponent.cpp 13.43 KiB
// Fill out your copyright notice in the Description page of Project Settings.
#include "OptiXLensComponent.h"
#include "Runtime/Engine/Classes/Engine/TextureRenderTargetCube.h"
#include "OptiXModule.h"
UOptiXLensComponent::UOptiXLensComponent(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
Radius1 = 0.8 * 100; // todo default values
Radius2 = 1.0 * 100;
LensRadius = 0.1 * 100;
LensType1 = ELensSideType::CONVEX;
LensType2 = ELensSideType::CONVEX;
LensThickness = 0.025 * 100;
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()
{
check(IsInRenderingThread());
OptiXGeometryInstance->SetFloat("radius", Radius1);
//UE_LOG(LogTemp, Display, TEXT("radius1 : %f"), Radius1);
OptiXGeometryInstance->SetFloat("radius2", Radius2);
//UE_LOG(LogTemp, Display, TEXT("radius2 : %f"), Radius2);
OptiXGeometryInstance->SetFloat("lensRadius", LensRadius);
//UE_LOG(LogTemp, Display, TEXT("lensradius : %f"), LensRadius);
OptiXGeometryInstance->SetFloat("halfCylinderLength", GetCylinderLength(LensThickness) / 2.0f);
//UE_LOG(LogTemp, Display, TEXT("halfCylinderLength : %f"), GetCylinderLength(LensThickness) / 2.0f);
OptiXGeometryInstance->SetInt("side1Type", static_cast<int32>(LensType1));
//UE_LOG(LogTemp, Display, TEXT("type1 : %i"), static_cast<int32>(LensType1));
OptiXGeometryInstance->SetInt("side2Type", static_cast<int32>(LensType2));
//UE_LOG(LogTemp, Display, TEXT("type2 : %i"), static_cast<int32>(LensType2));
double WL2 = FMath::Pow(CurrentWavelength / 1000.0, 2.0f);
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);
float Index = FMath::Sqrt(1 +
Def.B.X * WL2 / (WL2 - Def.C.X) +
Def.B.Y * WL2 / (WL2 - Def.C.Y) +
Def.B.Z * WL2 / (WL2 - Def.C.Z));
OptiXMaterial->SetFloat("refraction_index", Index);
MarkDirty();
}
void UOptiXLensComponent::UpdateOptiXComponent()