From 0dcaff90dba50200c8df6dfb1663d5020fc3272e Mon Sep 17 00:00:00 2001 From: rune stubbe Date: Thu, 11 Mar 2021 10:07:26 -0400 Subject: [PATCH] Fixed GeometryCollections having uninitialized vertex color when the source mesh has no colors. Fixed issue in BitStreamWriter_Writer when NumBits=32. #jira UE-110362 #rb graham.wihlidal #ROBOMERGE-OWNER: rune.stubbe #ROBOMERGE-AUTHOR: rune.stubbe #ROBOMERGE-SOURCE: CL 15675611 in //UE5/Release-5.0-EarlyAccess/... #ROBOMERGE-BOT: STARSHIP (Release-5.0-EarlyAccess -> Main) (v781-15675533) #ROBOMERGE-CONFLICT from-shelf [CL 15676219 by rune stubbe in ue5-main branch] --- .../GeometryCollection/GeometryCollectionConversion.cpp | 4 ++++ Engine/Shaders/Private/BitPacking.ush | 9 ++++++++- .../Developer/NaniteBuilder/Private/NaniteBuilder.cpp | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Engine/Plugins/Experimental/GeometryCollectionPlugin/Source/GeometryCollectionEditor/Private/GeometryCollection/GeometryCollectionConversion.cpp b/Engine/Plugins/Experimental/GeometryCollectionPlugin/Source/GeometryCollectionEditor/Private/GeometryCollection/GeometryCollectionConversion.cpp index 5e7e70bd49e2..4ec9e94dad93 100644 --- a/Engine/Plugins/Experimental/GeometryCollectionPlugin/Source/GeometryCollectionEditor/Private/GeometryCollection/GeometryCollectionConversion.cpp +++ b/Engine/Plugins/Experimental/GeometryCollectionPlugin/Source/GeometryCollectionEditor/Private/GeometryCollection/GeometryCollectionConversion.cpp @@ -72,6 +72,8 @@ void FGeometryCollectionConversion::AppendStaticMesh(const UStaticMesh* StaticMe UV[VertexOffset] = VertexBuffer.StaticMeshVertexBuffer.GetVertexUV(VertexIndex, 0); if (VertexBuffer.ColorVertexBuffer.GetNumVertices() == VertexCount) Color[VertexOffset] = VertexBuffer.ColorVertexBuffer.VertexColor(VertexIndex); + else + Color[VertexOffset] = FLinearColor::White; } // Triangle Indices @@ -654,6 +656,8 @@ void FGeometryCollectionConversion::AppendSkeletalMesh(const USkeletalMesh* Skel UV[VertexOffset] = VertexBuffers.StaticMeshVertexBuffer.GetVertexUV(VertexIndex, 0); if (VertexBuffers.ColorVertexBuffer.GetNumVertices() == VertexCount) Color[VertexOffset] = VertexBuffers.ColorVertexBuffer.VertexColor(VertexIndex); + else + Color[VertexOffset] = FLinearColor::White; } int32 InitialIndex = -1; diff --git a/Engine/Shaders/Private/BitPacking.ush b/Engine/Shaders/Private/BitPacking.ush index 7b44680054a3..a2424ccb5d39 100644 --- a/Engine/Shaders/Private/BitPacking.ush +++ b/Engine/Shaders/Private/BitPacking.ush @@ -278,6 +278,7 @@ void BitStreamWriter_Writer(inout FBitStreamWriterState State, uint Value, int N { State.BufferBits |= Value << State.BufferOffset; + // State.BufferOffset <= 31 uint NextBufferOffset = State.BufferOffset + NumBits; if (NextBufferOffset >= 32) @@ -285,7 +286,13 @@ void BitStreamWriter_Writer(inout FBitStreamWriterState State, uint Value, int N State.Output.InterlockedAnd(State.AlignedByteAddress, State.BufferMask); State.Output.InterlockedOr(State.AlignedByteAddress, State.BufferBits); State.BufferMask = 0; - State.BufferBits = Value >> (32 - State.BufferOffset); + + // Shifts are mod 32, so we need special handling when shift could be >= 32. + // State.BufferOffset can only be 0 here if NumBits >= 32 and therefore CompileTimeMaxBits >= 32. + if(CompileTimeMaxBits >= 32) + State.BufferBits = State.BufferOffset ? (Value >> (32 - State.BufferOffset)) : 0u; + else + State.BufferBits = Value >> (32 - State.BufferOffset); State.AlignedByteAddress += 4; } diff --git a/Engine/Source/Developer/NaniteBuilder/Private/NaniteBuilder.cpp b/Engine/Source/Developer/NaniteBuilder/Private/NaniteBuilder.cpp index d07dc0c73871..155cec7485ea 100644 --- a/Engine/Source/Developer/NaniteBuilder/Private/NaniteBuilder.cpp +++ b/Engine/Source/Developer/NaniteBuilder/Private/NaniteBuilder.cpp @@ -24,7 +24,7 @@ // differences, etc.) replace the version GUID below with a new one. // In case of merge conflicts with DDC versions, you MUST generate a new GUID // and set this new GUID as the version. -#define NANITE_DERIVEDDATA_VER TEXT("3AAB0510-8F1D-59F4-B3C9-91FADBE10CB5") +#define NANITE_DERIVEDDATA_VER TEXT("3ABB0516-8F1E-59F6-B3CA-91FDDBF10CB5") namespace Nanite {