Skip to content

Instantly share code, notes, and snippets.

@BlurryLight
Created September 15, 2023 16:09
Show Gist options
  • Save BlurryLight/28852a23ca793185778bdf3b3172c32b to your computer and use it in GitHub Desktop.
Save BlurryLight/28852a23ca793185778bdf3b3172c32b to your computer and use it in GitHub Desktop.
UE4.26 ISM FP32 support
---
.../Components/InstancedStaticMeshComponent.h | 5 +++++
.../Runtime/Engine/Private/InstancedStaticMesh.cpp | 13 +++++++++++--
.../Runtime/Engine/Public/StaticMeshResources.h | 3 ++-
3 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/Engine/Source/Runtime/Engine/Classes/Components/InstancedStaticMeshComponent.h b/Engine/Source/Runtime/Engine/Classes/Components/InstancedStaticMeshComponent.h
index d6694d8ce..af60349c1 100644
--- a/Engine/Source/Runtime/Engine/Classes/Components/InstancedStaticMeshComponent.h
+++ b/Engine/Source/Runtime/Engine/Classes/Components/InstancedStaticMeshComponent.h
@@ -133,6 +133,11 @@ class ENGINE_API UInstancedStaticMeshComponent : public UStaticMeshComponent
UPROPERTY(EditAnywhere, SkipSerialization, DisplayName="Instances", Category=Instances, meta=(MakeEditWidget=true, EditFixedOrder))
TArray<FInstancedStaticMeshInstanceData> PerInstanceSMData;
+ // ++
+ UPROPERTY(EditAnywhere, Category=Instances, AdvancedDisplay)
+ bool bUseFP32Transformation;
+ // --
+
/** Defines the number of floats that will be available per instance for custom data */
UPROPERTY(EditAnywhere, Category=Instances, AdvancedDisplay)
int32 NumCustomDataFloats;
diff --git a/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp b/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp
index 9397bb3d4..e34745048 100644
--- a/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp
+++ b/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp
@@ -1388,6 +1388,7 @@ UInstancedStaticMeshComponent::UInstancedStaticMeshComponent(const FObjectInitia
BodyInstance.bSimulatePhysics = false;
bDisallowMeshPaintPerInstance = true;
+ bUseFP32Transformation = false; //++
}
UInstancedStaticMeshComponent::UInstancedStaticMeshComponent(FVTableHelper& Helper)
@@ -1484,7 +1485,7 @@ void UInstancedStaticMeshComponent::FlushInstanceUpdateCommands()
{
InstanceUpdateCmdBuffer.Reset();
- FStaticMeshInstanceData RenderInstanceData = FStaticMeshInstanceData(GVertexElementTypeSupport.IsSupported(VET_Half2));
+ FStaticMeshInstanceData RenderInstanceData = FStaticMeshInstanceData(GVertexElementTypeSupport.IsSupported(VET_Half2) && !bUseFP32Transformation ); // change
BuildRenderData(RenderInstanceData, PerInstanceRenderData->HitProxies);
PerInstanceRenderData->UpdateFromPreallocatedData(RenderInstanceData);
}
@@ -2907,7 +2908,7 @@ void UInstancedStaticMeshComponent::InitPerInstanceRenderData(bool InitializeFro
else
{
TArray<TRefCountPtr<HHitProxy>> HitProxies;
- FStaticMeshInstanceData InstanceBufferData = FStaticMeshInstanceData(GVertexElementTypeSupport.IsSupported(VET_Half2));
+ FStaticMeshInstanceData InstanceBufferData = FStaticMeshInstanceData(GVertexElementTypeSupport.IsSupported(VET_Half2) && !bUseFP32Transformation ); // -change
if (InitializeFromCurrentData)
{
@@ -3134,6 +3135,14 @@ void UInstancedStaticMeshComponent::PostEditChangeChainProperty(FPropertyChanged
InstanceUpdateCmdBuffer.Edit();
MarkRenderStateDirty();
}
+ //++
+ else if (PropertyChangedEvent.PropertyChain.GetActiveMemberNode()->GetValue()->GetFName() ==
+ "bUseFP32Transformation")
+ {
+ InstanceUpdateCmdBuffer.Edit();
+ MarkRenderStateDirty();
+ }
+ //--
}
Super::PostEditChangeChainProperty(PropertyChangedEvent);
}
diff --git a/Engine/Source/Runtime/Engine/Public/StaticMeshResources.h b/Engine/Source/Runtime/Engine/Public/StaticMeshResources.h
index 9957e0f60..c85c5d89b 100644
--- a/Engine/Source/Runtime/Engine/Public/StaticMeshResources.h
+++ b/Engine/Source/Runtime/Engine/Public/StaticMeshResources.h
@@ -1187,7 +1187,8 @@ public:
* @param bInUseHalfFloat - true if device has support for half float in vertex arrays
*/
FStaticMeshInstanceData(bool bInUseHalfFloat)
- : bUseHalfFloat(PLATFORM_BUILTIN_VERTEX_HALF_FLOAT || bInUseHalfFloat)
+ // : bUseHalfFloat(PLATFORM_BUILTIN_VERTEX_HALF_FLOAT && bInUseHalfFloat) //+
+ : bUseHalfFloat(PLATFORM_BUILTIN_VERTEX_HALF_FLOAT && bInUseHalfFloat)
{
AllocateBuffers(0);
}
--
2.42.0.windows.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment