Created
November 23, 2021 22:23
-
-
Save alexgeek/58e86900a65da52c5bf0e44b792828ae to your computer and use it in GitHub Desktop.
VR Spectator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Add in a BP function library: | |
| /** | |
| * Create a transient render target. This version exposes bForceLinearGamma. | |
| */ | |
| UFUNCTION(BlueprintCallable, Category = "Liv", meta = (WorldContext = "WorldContextObject")) | |
| static UTextureRenderTarget2D* CreateRenderTarget2D( | |
| UObject* WorldContextObject, | |
| int32 Width, | |
| int32 Height, | |
| bool bForceLinearGamma = true, | |
| FName Name = NAME_None, | |
| ETextureRenderTargetFormat Format = ETextureRenderTargetFormat::RTF_RGBA8, | |
| FLinearColor ClearColor = FLinearColor::Black, | |
| float TargetGamma = 0.0f); | |
| // ... | |
| UTextureRenderTarget2D* ULivBlueprintFunctionLibrary::CreateRenderTarget2D( | |
| UObject* WorldContextObject, | |
| int32 Width, | |
| int32 Height, | |
| bool bForceLinearGamma, | |
| FName Name, | |
| ETextureRenderTargetFormat Format, | |
| FLinearColor ClearColor, | |
| float TargetGamma) | |
| { | |
| UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull); | |
| if (Width > 0 && Height > 0 && World) | |
| { | |
| UTextureRenderTarget2D* NewRenderTarget2D = NewObject<UTextureRenderTarget2D>(GetTransientPackage(), Name); | |
| check(NewRenderTarget2D); | |
| NewRenderTarget2D->RenderTargetFormat = Format; | |
| NewRenderTarget2D->ClearColor = ClearColor; | |
| NewRenderTarget2D->bAutoGenerateMips = false; | |
| NewRenderTarget2D->TargetGamma = TargetGamma; | |
| NewRenderTarget2D->bForceLinearGamma = bForceLinearGamma; | |
| NewRenderTarget2D->InitAutoFormat(Width, Height); | |
| NewRenderTarget2D->UpdateResourceImmediate(true); | |
| return NewRenderTarget2D; | |
| } | |
| return nullptr; | |
| } | |
| // Call with bForceLinearGamma = false (RTF_RGBA8 format worked well for me) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment