Files
UnrealEngineUWP/Engine/Source/Editor/VirtualTexturingEditor/Private/RuntimeVirtualTextureThumbnailRenderer.cpp
Ola Olsson 69d2af54aa Refactored GPU-Scene to store per-view dynamic primitives (for all views) in the one and primitive data buffer, after the regular primitives.
- Added step after dynamic primitives are gathered to allocate a range in GPU scene for the dynamic primitives.
- Moved more GPU-Scene functionality to member functions to clean up references to internal data
- Removed the PrimitiveShaderDataBuffer/Texture from FSceneViewState
- Removed OneFramePrimitiveShaderDataBuffer/Texture from FViewInfo
- Encapsulated the collection of dynamic primitive data for upload to avoid uploading twice and prepare for parallel upload.

#rb Krzysztof.Narkowicz,graham.wihlidal

[CL 14785776 by Ola Olsson in ue5-main branch]
2020-11-19 05:23:44 -04:00

103 lines
4.1 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "RuntimeVirtualTextureThumbnailRenderer.h"
#include "Components/RuntimeVirtualTextureComponent.h"
#include "MaterialShared.h"
#include "RenderingThread.h"
#include "RenderGraphBuilder.h"
#include "SceneInterface.h"
#include "VT/RuntimeVirtualTexture.h"
#include "VT/RuntimeVirtualTextureRender.h"
#include "UnrealClient.h"
#include "UObject/UObjectIterator.h"
namespace
{
/** Find a matching component for this URuntimeVirtualTexture. */
URuntimeVirtualTextureComponent* FindComponent(URuntimeVirtualTexture* RuntimeVirtualTexture)
{
for (TObjectIterator<URuntimeVirtualTextureComponent> It; It; ++It)
{
URuntimeVirtualTextureComponent* RuntimeVirtualTextureComponent = *It;
if (RuntimeVirtualTextureComponent->GetVirtualTexture() == RuntimeVirtualTexture)
{
return RuntimeVirtualTextureComponent;
}
}
return nullptr;
}
}
URuntimeVirtualTextureThumbnailRenderer::URuntimeVirtualTextureThumbnailRenderer(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}
bool URuntimeVirtualTextureThumbnailRenderer::CanVisualizeAsset(UObject* Object)
{
URuntimeVirtualTexture* RuntimeVirtualTexture = Cast<URuntimeVirtualTexture>(Object);
// We need a matching URuntimeVirtualTextureComponent in a Scene to be able to render a thumbnail
URuntimeVirtualTextureComponent* RuntimeVirtualTextureComponent = FindComponent(RuntimeVirtualTexture);
if (RuntimeVirtualTextureComponent != nullptr)
{
FSceneInterface* Scene = RuntimeVirtualTextureComponent->GetScene();
if (Scene != nullptr && RuntimeVirtualTexture::IsSceneReadyToRender(Scene->GetRenderScene()))
{
return true;
}
}
return false;
}
void URuntimeVirtualTextureThumbnailRenderer::Draw(UObject* Object, int32 X, int32 Y, uint32 Width, uint32 Height, FRenderTarget* RenderTarget, FCanvas* Canvas, bool bAdditionalViewFamily)
{
//todo[vt]: Handle case where a null or floating point render target is passed in. (This happens on package save.)
if (RenderTarget->GetRenderTargetTexture() == nullptr || RenderTarget->GetRenderTargetTexture()->GetFormat() != PF_B8G8R8A8)
{
return;
}
URuntimeVirtualTexture* RuntimeVirtualTexture = Cast<URuntimeVirtualTexture>(Object);
URuntimeVirtualTextureComponent* RuntimeVirtualTextureComponent = FindComponent(RuntimeVirtualTexture);
FSceneInterface* Scene = RuntimeVirtualTextureComponent != nullptr ? RuntimeVirtualTextureComponent->GetScene() : nullptr;
check(Scene != nullptr);
const FBox2D DestBox = FBox2D(FVector2D(X, Y), FVector2D(Width, Height));
const FTransform Transform = RuntimeVirtualTextureComponent->GetComponentTransform();
const FBox Bounds = RuntimeVirtualTextureComponent->Bounds.GetBox();
const uint32 VirtualTextureSceneIndex = RuntimeVirtualTexture::GetRuntimeVirtualTextureSceneIndex_GameThread(RuntimeVirtualTextureComponent);
const ERuntimeVirtualTextureMaterialType MaterialType = RuntimeVirtualTexture->GetMaterialType();
FVTProducerDescription VTDesc;
RuntimeVirtualTexture->GetProducerDescription(VTDesc, URuntimeVirtualTexture::FInitSettings(), Transform);
const int32 MaxLevel = (int32)FMath::CeilLogTwo(FMath::Max(VTDesc.BlockWidthInTiles, VTDesc.BlockHeightInTiles));
ENQUEUE_RENDER_COMMAND(BakeStreamingTextureTileCommand)(
[Scene, VirtualTextureSceneIndex, MaterialType, RenderTarget, DestBox, Transform, Bounds, MaxLevel](FRHICommandListImmediate& RHICmdList)
{
FMaterialRenderProxy::UpdateDeferredCachedUniformExpressions();
RuntimeVirtualTexture::FRenderPageBatchDesc Desc;
Desc.Scene = Scene->GetRenderScene();
Desc.RuntimeVirtualTextureMask = 1 << VirtualTextureSceneIndex;
Desc.UVToWorld = Transform;
Desc.WorldBounds = Bounds;
Desc.MaterialType = MaterialType;
Desc.MaxLevel = MaxLevel;
Desc.bClearTextures = true;
Desc.bIsThumbnails = true;
Desc.DebugType = ERuntimeVirtualTextureDebugType::None;
Desc.NumPageDescs = 1;
Desc.Targets[0].Texture = RenderTarget->GetRenderTargetTexture();
Desc.PageDescs[0].DestBox[0] = DestBox;
Desc.PageDescs[0].UVRange = FBox2D(FVector2D(0, 0), FVector2D(1, 1));
Desc.PageDescs[0].vLevel = MaxLevel;
RuntimeVirtualTexture::RenderPagesStandAlone(RHICmdList, Desc);
});
}