Files
UnrealEngineUWP/Engine/Source/Developer/MeshUtilitiesCommon/Public/MeshUtilitiesCommon.h
danny couture edddecfb8c Improve performance of UV island packing
- Test rows from longest to shortest to get rid of one inner loop in the hot path
  - Add lookup table to skip another free segment inner loop in the hot path
  - Added island hashing to skip directly to last known best position
  - Split loops, simplify code and add comments for clarity
  - Reduce data copying and clearing to working area only
  - Multithreaded initial scale search when complexity is high enough
  - Added a segment grid along the Y axis for more efficient search of taller island
  - Added ability to log packing stats per island in Insights to understand algorithmic behavior
  - Now able to pack 300k islands on a 2048x2048 texture in under 60s using 4 cores

  - Improvements made while maintaining backward compatibility (same output as before)
     - 52m16s -> 80s for DATASET-0002a (foliage)
     - 148s -> 105s for DATASET-0008a
     - 333s -> 8.5s for DATASET-0020a (house)  using 2048x2048 MinResolution
  - Improvements made while activating segments in 2D including packing efficiency improvements
     - 52m16s -> 14s (efficiency 95.52% -> 97.68%) for DATASET-0002a (foliage)
     - 148s -> 105s (efficiency 63.3% -> 63.3%) for DATASET-0008a
     - 333s -> 6s  (efficiency 93.5% -> 98.57%) for DATASET-0020 (house) using 2048x2048 MinResolution

From dev-enterprise[at]9485619

#jira UE-82137
#rb Johan.Duparc, JeanMichel.Dignard

#ROBOMERGE-SOURCE: CL 9730840 in //UE4/Release-4.24/...
#ROBOMERGE-BOT: RELEASE (Release-4.24 -> Main) (v539-9700858)

[CL 9730842 by danny couture in Main branch]
2019-10-21 06:30:37 -04:00

85 lines
2.1 KiB
C++

// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
enum class ELightmapUVVersion : int32
{
BitByBit = 0,
Segments = 1,
SmallChartPacking = 2,
ScaleChartsOrderingFix = 3,
ChartJoiningLFix = 4,
Allocator2DFlipFix = 5,
ConsiderLightmapPadding = 6,
ForceLightmapPadding = 7,
Segments2D = 8,
Latest = Segments2D
};
/** Helper struct for building acceleration structures. */
struct FIndexAndZ
{
float Z;
int32 Index;
/** Default constructor. */
FIndexAndZ() {}
/** Initialization constructor. */
FIndexAndZ(int32 InIndex, FVector V)
{
Z = 0.30f * V.X + 0.33f * V.Y + 0.37f * V.Z;
Index = InIndex;
}
};
/** Sorting function for vertex Z/index pairs. */
struct FCompareIndexAndZ
{
FORCEINLINE bool operator()(FIndexAndZ const& A, FIndexAndZ const& B) const { return A.Z < B.Z; }
};
/**
* Returns true if the specified points are about equal
*/
inline bool PointsEqual(const FVector& V1, const FVector& V2, float ComparisonThreshold)
{
if (FMath::Abs(V1.X - V2.X) > ComparisonThreshold
|| FMath::Abs(V1.Y - V2.Y) > ComparisonThreshold
|| FMath::Abs(V1.Z - V2.Z) > ComparisonThreshold)
{
return false;
}
return true;
}
namespace TriangleUtilities
{
/*
* This function compute the area of a triangle, it will return zero if the triangle is degenerated
*/
static float ComputeTriangleArea(const FVector& PointA, const FVector& PointB, const FVector& PointC)
{
return FVector::CrossProduct((PointB - PointA), (PointC - PointA)).Size() / 2.0f;
}
/*
* This function compute the angle of a triangle corner, it will return zero if the triangle is degenerated
*/
static float ComputeTriangleCornerAngle(const FVector& PointA, const FVector& PointB, const FVector& PointC)
{
FVector E1 = (PointB - PointA);
FVector E2 = (PointC - PointA);
//Normalize both edges (unit vector) of the triangle so we get a dotProduct result that will be a valid acos input [-1, 1]
if (!E1.Normalize() || !E2.Normalize())
{
//Return a null ratio if the polygon is degenerate
return 0.0f;
}
float DotProduct = FVector::DotProduct(E1, E2);
return FMath::Acos(DotProduct);
}
}