You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
* Fixed a crash that occurred in the baking step when cancelling a scene capture which was triggered by changing an option which invalidated all photo sets (i.e., render capture resolution or capture anti aliasing). This was occurring because the baking step proceeded after the scene capture cancellation and the needed photosets were empty. * Fixed a crash which can happen if you have no channel enabled, change cleanup tolerance from 0 to 1 and then enable the BaseColor channel. This was fixed by changing the behavior of the Cleanup Threshold property, if its positive the DeviceDepth capture is enabled and its disabled otherwise, previously we also required that another channel was enabled which led to the crash in the baking step. The new semantics are easier to understand in the code and and is probably an improvement to the UX as well since the Cleanup Threshold property behavior does not depend on other properties. * Improved the scene capture cancellation: Users can now cancel the scene capture when the tool is starting up which is better UX since if they picked slow settings they don't intend to reuse, the capture can be cancelled, also, the code is simpler. Changed the behavior of the BakeRC tool properties so that after cancellation the completed captures with the desired settings are enabled. The old behavior where cancellation was documented to restore old results was broken and cannot be made to work unless we store the old results in a separate scene capture but for high capture resolutions that would require a lot of memory. When the SceneCapture is cancelled the channels which were pending and didn't complete are logged in the Output Log in case the user forgets which ones were enabled. * Simplified the code in various places: Added `operator[](ERenderCaptureType)` to structs with per-capture data, and use it to simplify many places where we previously checked channels individually. Added conversion functions from tool properties/geometry script parameters to the render capture parameters. Removed old confusing logic that determined if a capture had been updated by tracking the number of photos in each photoset with a new system based on a new per-capture pending state. Deprecated a bunch of functions which are no longer useful or which used the wrong types (e.g., `FRenderCaptureUpdate` was added because I hadn't noticed `FRenderCaptureTypeFlags`). Changed the defaults in `FSceneCapturePhotoSet` so that the DeviceDepth capture is off, its an advanced feature and the defaults are intended to make the class friendly to new developers #rb lonnie.li [CL 26569987 by matija kecman in ue5-main branch]
276 lines
8.5 KiB
C++
276 lines
8.5 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "Scene/SceneCapturePhotoSet.h"
|
|
#include "Sampling/MeshBakerCommon.h"
|
|
#include "Image/ImageInfilling.h"
|
|
#include "Baking/BakingTypes.h"
|
|
#include "DynamicMesh/MeshTangents.h"
|
|
#include "CoreMinimal.h"
|
|
|
|
class UTexture2D;
|
|
class AActor;
|
|
|
|
namespace UE
|
|
{
|
|
namespace Geometry
|
|
{
|
|
|
|
class FMeshMapBaker;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MODELINGCOMPONENTS_API FRenderCaptureOcclusionHandler
|
|
{
|
|
public:
|
|
FRenderCaptureOcclusionHandler(FImageDimensions Dimensions);
|
|
|
|
void RegisterSample(const FVector2i& ImageCoords, bool bSampleValid);
|
|
|
|
void PushInfillRequired(bool bInfillRequired);
|
|
|
|
void ComputeAndApplyInfill(TArray<TUniquePtr<TImageBuilder<FVector4f>>>& Images);
|
|
|
|
private:
|
|
|
|
struct FSampleStats {
|
|
uint16 NumValid = 0;
|
|
uint16 NumInvalid = 0;
|
|
|
|
// These are required by the TMarchingPixelInfill implementation
|
|
bool operator==(const FSampleStats& Other) const;
|
|
bool operator!=(const FSampleStats& Other) const;
|
|
FSampleStats& operator+=(const FSampleStats& Other);
|
|
static FSampleStats Zero();
|
|
};
|
|
|
|
void ComputeInfill();
|
|
|
|
void ApplyInfill(TImageBuilder<FVector4f>& Image) const;
|
|
|
|
// Collect some sample stats per pixel, used to determine if a pixel requires infill or not
|
|
TImageBuilder<FSampleStats> SampleStats;
|
|
|
|
// InfillRequire[i] indicates if the i-th image passed to ComputeAndApplyInfill needs infill
|
|
TArray<bool> InfillRequired;
|
|
|
|
TMarchingPixelInfill<FSampleStats> Infill;
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class MODELINGCOMPONENTS_API FSceneCapturePhotoSetSampler : public FMeshBakerDynamicMeshSampler
|
|
{
|
|
public:
|
|
FSceneCapturePhotoSetSampler(
|
|
FSceneCapturePhotoSet* SceneCapture,
|
|
float ValidSampleDepthThreshold,
|
|
const FDynamicMesh3* Mesh,
|
|
const FDynamicMeshAABBTree3* Spatial,
|
|
const FMeshTangentsd* Tangents);
|
|
|
|
UE_NONCOPYABLE(FSceneCapturePhotoSetSampler);
|
|
|
|
virtual bool SupportsCustomCorrespondence() const override;
|
|
|
|
// Warning: Expects that Sample.BaseSample.SurfacePoint and Sample.BaseNormal are set when the function is called
|
|
virtual void* ComputeCustomCorrespondence(const FMeshUVSampleInfo& SampleInfo, FMeshMapEvaluator::FCorrespondenceSample& Sample) const override;
|
|
|
|
virtual bool IsValidCorrespondence(const FMeshMapEvaluator::FCorrespondenceSample& Sample) const override;
|
|
|
|
private:
|
|
FSceneCapturePhotoSet* SceneCapture = nullptr;
|
|
float ValidSampleDepthThreshold = 0;
|
|
TFunction<bool(const FVector3d&, const FVector3d&)> VisibilityFunction;
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct MODELINGCOMPONENTS_API FSceneCaptureConfig
|
|
{
|
|
int32 RenderCaptureImageSize = 1024;
|
|
bool bAntiAliasing = false;
|
|
double FieldOfViewDegrees = 45.0;
|
|
double NearPlaneDist = 1.0;
|
|
|
|
FRenderCaptureTypeFlags Flags = FRenderCaptureTypeFlags::None();
|
|
|
|
bool operator==(const FSceneCaptureConfig&) const;
|
|
bool operator!=(const FSceneCaptureConfig&) const;
|
|
};
|
|
|
|
MODELINGCOMPONENTS_API
|
|
void ConfigureSceneCapture(
|
|
const TUniquePtr<FSceneCapturePhotoSet>& SceneCapture,
|
|
const TArray<TObjectPtr<AActor>>& Actors,
|
|
const FSceneCaptureConfig& Config,
|
|
bool bAllowCancel);
|
|
|
|
MODELINGCOMPONENTS_API
|
|
FRenderCaptureTypeFlags UpdateSceneCapture(
|
|
const TUniquePtr<FSceneCapturePhotoSet>& SceneCapture,
|
|
const TArray<TObjectPtr<AActor>>& Actors,
|
|
const FSceneCaptureConfig& DesiredConfig,
|
|
bool bAllowCancel);
|
|
|
|
MODELINGCOMPONENTS_API
|
|
FSceneCaptureConfig GetSceneCaptureConfig(
|
|
const TUniquePtr<FSceneCapturePhotoSet>& SceneCapture,
|
|
FSceneCapturePhotoSet::ECaptureTypeStatus QueryStatus = FSceneCapturePhotoSet::ECaptureTypeStatus::Computed);
|
|
|
|
// Return a render capture baker, note the lifetime of all arguments such match the lifetime of the returned baker
|
|
MODELINGCOMPONENTS_API
|
|
TUniquePtr<FMeshMapBaker> MakeRenderCaptureBaker(
|
|
FDynamicMesh3* BaseMesh,
|
|
TSharedPtr<FMeshTangentsd, ESPMode::ThreadSafe> BaseMeshTangents,
|
|
TSharedPtr<TArray<int32>, ESPMode::ThreadSafe> BaseMeshUVCharts,
|
|
FSceneCapturePhotoSet* SceneCapture,
|
|
FSceneCapturePhotoSetSampler* Sampler,
|
|
FRenderCaptureTypeFlags PendingBake,
|
|
int32 TargetUVLayer,
|
|
EBakeTextureResolution TextureImageSize,
|
|
EBakeTextureSamplesPerPixel SamplesPerPixel,
|
|
FRenderCaptureOcclusionHandler* OcclusionHandler);
|
|
|
|
struct MODELINGCOMPONENTS_API FRenderCaptureTextures
|
|
{
|
|
UTexture2D* BaseColorMap = nullptr;
|
|
UTexture2D* NormalMap = nullptr;
|
|
UTexture2D* PackedMRSMap = nullptr;
|
|
UTexture2D* MetallicMap = nullptr;
|
|
UTexture2D* RoughnessMap = nullptr;
|
|
UTexture2D* SpecularMap = nullptr;
|
|
UTexture2D* EmissiveMap = nullptr;
|
|
UTexture2D* OpacityMap = nullptr;
|
|
UTexture2D* SubsurfaceColorMap = nullptr;
|
|
};
|
|
|
|
// Note: The source data in the textures is *not* updated by this function
|
|
MODELINGCOMPONENTS_API
|
|
void GetTexturesFromRenderCaptureBaker(
|
|
const TUniquePtr<FMeshMapBaker>& Baker,
|
|
FRenderCaptureTextures& TexturesOut);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// The following is all deprecated
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
PRAGMA_DISABLE_DEPRECATION_WARNINGS
|
|
|
|
struct UE_DEPRECATED(5.3, "FRenderCaptureOptions is only used by deprecated functions, see those deprecation notes for more info.") MODELINGCOMPONENTS_API FRenderCaptureOptions
|
|
{
|
|
//
|
|
// Material approximation settings
|
|
//
|
|
|
|
int32 RenderCaptureImageSize = 1024;
|
|
bool bAntiAliasing = false;
|
|
|
|
// render capture parameters
|
|
double FieldOfViewDegrees = 45.0;
|
|
double NearPlaneDist = 1.0;
|
|
|
|
//
|
|
// Material output settings
|
|
//
|
|
|
|
bool bBakeBaseColor = true;
|
|
bool bBakeRoughness = true;
|
|
bool bBakeMetallic = true;
|
|
bool bBakeSpecular = true;
|
|
bool bBakeEmissive = true;
|
|
bool bBakeNormalMap = true;
|
|
bool bBakeOpacity = true;
|
|
bool bBakeSubsurfaceColor = true;
|
|
bool bBakeDeviceDepth = true;
|
|
|
|
bool bUsePackedMRS = true;
|
|
};
|
|
|
|
struct UE_DEPRECATED(5.3, "FRenderCaptureUpdate is only used by deprecated functions, see those deprecation notes for more info.") MODELINGCOMPONENTS_API FRenderCaptureUpdate
|
|
{
|
|
// Default to true so that we can use the default value to trigger all update code paths
|
|
bool bUpdatedBaseColor = true;
|
|
bool bUpdatedRoughness = true;
|
|
bool bUpdatedMetallic = true;
|
|
bool bUpdatedSpecular = true;
|
|
bool bUpdatedEmissive = true;
|
|
bool bUpdatedNormalMap = true;
|
|
bool bUpdatedOpacity = true;
|
|
bool bUpdatedSubsurfaceColor = true;
|
|
bool bUpdatedDeviceDepth = true;
|
|
bool bUpdatedPackedMRS = true;
|
|
};
|
|
|
|
|
|
/**
|
|
* This function computes the SceneCapture for the first time
|
|
*/
|
|
UE_DEPRECATED(5.3, "Please use ConfigureSceneCapture and FSceneCapturePhotoSet::Compute instead.")
|
|
MODELINGCOMPONENTS_API
|
|
TUniquePtr<FSceneCapturePhotoSet> CapturePhotoSet(
|
|
const TArray<TObjectPtr<AActor>>& Actors,
|
|
const FRenderCaptureOptions& Options,
|
|
FRenderCaptureUpdate& Update,
|
|
bool bAllowCancel);
|
|
|
|
/**
|
|
* This function efficiently updates the given SceneCapture and returns a struct indicating which channels were updated
|
|
*
|
|
* - If the requested Options and Actors have already been captured the call is a no-op
|
|
* - If the given Options disable existing capture channels then the call just clears the corresponding photo sets
|
|
* - If the given Options enable a new capture channel then the new photos set are captured and added to the SceneCapture
|
|
* - If the given Actors are different the ones cached in the SceneCapture, or if the given Options changes a parameter
|
|
* affecting all photo sets (e.g., photo resolution), then all the photo sets are cleared and recomputed
|
|
*/
|
|
UE_DEPRECATED(5.3, "Please use UpdateSceneCapture instead.")
|
|
MODELINGCOMPONENTS_API
|
|
FRenderCaptureUpdate UpdatePhotoSets(
|
|
const TUniquePtr<FSceneCapturePhotoSet>& SceneCapture,
|
|
const TArray<TObjectPtr<AActor>>& Actors,
|
|
const FRenderCaptureOptions& Options,
|
|
bool bAllowCancel);
|
|
|
|
UE_DEPRECATED(5.3, "Please use GetSceneCaptureConfig instead.")
|
|
MODELINGCOMPONENTS_API
|
|
FRenderCaptureOptions GetComputedPhotoSetOptions(const TUniquePtr<FSceneCapturePhotoSet>& SceneCapture);
|
|
|
|
|
|
// Return a render capture baker, note the lifetime of all arguments such match the lifetime of the returned baker
|
|
UE_DEPRECATED(5.3, "Please use the overload where PendingBake has type FRenderCaptureTypeFlags instead.")
|
|
MODELINGCOMPONENTS_API
|
|
TUniquePtr<FMeshMapBaker> MakeRenderCaptureBaker(
|
|
FDynamicMesh3* BaseMesh,
|
|
TSharedPtr<FMeshTangentsd, ESPMode::ThreadSafe> BaseMeshTangents,
|
|
TSharedPtr<TArray<int32>, ESPMode::ThreadSafe> BaseMeshUVCharts,
|
|
FSceneCapturePhotoSet* SceneCapture,
|
|
FSceneCapturePhotoSetSampler* Sampler,
|
|
FRenderCaptureOptions PendingBake,
|
|
int32 TargetUVLayer,
|
|
EBakeTextureResolution TextureImageSize,
|
|
EBakeTextureSamplesPerPixel SamplesPerPixel,
|
|
FRenderCaptureOcclusionHandler* OcclusionHandler);
|
|
|
|
PRAGMA_ENABLE_DEPRECATION_WARNINGS
|
|
|
|
} // end namespace Geometry
|
|
} // end namespace UE
|