You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
- add FRayTracingGeometry structures to FMeshRenderBufferSet for primary and secondary triangle indices
- add UpdateRaytracingGeometryIfEnabled() function which rebuilds these raytracing data structures. This does a full rebuild, not clear if any kind of incremental update is possible currently, to revisit in future.
- call the above in the various places where we modify the existing index/vertex buffers.
- add UPrimitiveComponent::GetDynamicRayTracingInstances() implementation, mirrors GetDynamicMeshElements() implementation, uses new DrawRayTracingBatch() function
#rb juan.canada
#rnx
#jira none
#preflight 6157507e2363e400012ed95f
#ROBOMERGE-AUTHOR: ryan.schmidt
#ROBOMERGE-SOURCE: CL 17696127 in //UE5/Release-5.0/... via CL 17696138
#ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v875-17642767)
#ROBOMERGE[STARSHIP]: UE5-Main
[CL 17696156 by ryan schmidt in ue5-release-engine-test branch]
196 lines
4.5 KiB
C++
196 lines
4.5 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "Components/BaseDynamicMeshComponent.h"
|
|
#include "Components/BaseDynamicMeshSceneProxy.h"
|
|
|
|
using namespace UE::Geometry;
|
|
|
|
UBaseDynamicMeshComponent::UBaseDynamicMeshComponent(const FObjectInitializer& ObjectInitializer)
|
|
: Super(ObjectInitializer)
|
|
{
|
|
}
|
|
|
|
|
|
|
|
#if WITH_EDITOR
|
|
void UBaseDynamicMeshComponent::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
|
|
{
|
|
Super::PostEditChangeProperty(PropertyChangedEvent);
|
|
|
|
const FName PropName = PropertyChangedEvent.GetPropertyName();
|
|
if ( (PropName == GET_MEMBER_NAME_CHECKED(UBaseDynamicMeshComponent, bEnableRaytracing)) )
|
|
{
|
|
OnRaytracingStateChanged();
|
|
}
|
|
}
|
|
#endif
|
|
|
|
|
|
void UBaseDynamicMeshComponent::SetShadowsEnabled(bool bEnabled)
|
|
{
|
|
// finish any drawing so that we can be certain our SceneProxy is no longer in use before we rebuild it below
|
|
FlushRenderingCommands();
|
|
|
|
SetCastShadow(bEnabled);
|
|
//bCastDynamicShadow = bEnabled;
|
|
|
|
// apparently SceneProxy has to be fully rebuilt to change shadow state
|
|
|
|
// this marks the SceneProxy for rebuild, but not immediately, and possibly allows bad things to happen
|
|
// before the end of the frame
|
|
//MarkRenderStateDirty();
|
|
|
|
// force immediate rebuild of the SceneProxy
|
|
if (IsRegistered())
|
|
{
|
|
ReregisterComponent();
|
|
}
|
|
}
|
|
|
|
|
|
void UBaseDynamicMeshComponent::SetOverrideRenderMaterial(UMaterialInterface* Material)
|
|
{
|
|
if (OverrideRenderMaterial != Material)
|
|
{
|
|
OverrideRenderMaterial = Material;
|
|
NotifyMaterialSetUpdated();
|
|
}
|
|
}
|
|
|
|
void UBaseDynamicMeshComponent::ClearOverrideRenderMaterial()
|
|
{
|
|
if (OverrideRenderMaterial != nullptr)
|
|
{
|
|
OverrideRenderMaterial = nullptr;
|
|
NotifyMaterialSetUpdated();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UBaseDynamicMeshComponent::SetSecondaryRenderMaterial(UMaterialInterface* Material)
|
|
{
|
|
if (SecondaryRenderMaterial != Material)
|
|
{
|
|
SecondaryRenderMaterial = Material;
|
|
NotifyMaterialSetUpdated();
|
|
}
|
|
}
|
|
|
|
void UBaseDynamicMeshComponent::ClearSecondaryRenderMaterial()
|
|
{
|
|
if (SecondaryRenderMaterial != nullptr)
|
|
{
|
|
SecondaryRenderMaterial = nullptr;
|
|
NotifyMaterialSetUpdated();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void UBaseDynamicMeshComponent::SetSecondaryBuffersVisibility(bool bSecondaryVisibility)
|
|
{
|
|
bDrawSecondaryBuffers = bSecondaryVisibility;
|
|
}
|
|
|
|
bool UBaseDynamicMeshComponent::GetSecondaryBuffersVisibility() const
|
|
{
|
|
return bDrawSecondaryBuffers;
|
|
}
|
|
|
|
|
|
void UBaseDynamicMeshComponent::SetEnableRaytracing(bool bSetEnabled)
|
|
{
|
|
if (bEnableRaytracing != bSetEnabled)
|
|
{
|
|
bEnableRaytracing = bSetEnabled;
|
|
OnRaytracingStateChanged();
|
|
}
|
|
}
|
|
|
|
bool UBaseDynamicMeshComponent::GetEnableRaytracing() const
|
|
{
|
|
return bEnableRaytracing;
|
|
}
|
|
|
|
void UBaseDynamicMeshComponent::OnRaytracingStateChanged()
|
|
{
|
|
// finish any drawing so that we can be certain our SceneProxy is no longer in use before we rebuild it below
|
|
FlushRenderingCommands();
|
|
|
|
// force immediate rebuild of the SceneProxy
|
|
if (IsRegistered())
|
|
{
|
|
ReregisterComponent();
|
|
}
|
|
}
|
|
|
|
|
|
int32 UBaseDynamicMeshComponent::GetNumMaterials() const
|
|
{
|
|
return BaseMaterials.Num();
|
|
}
|
|
|
|
UMaterialInterface* UBaseDynamicMeshComponent::GetMaterial(int32 ElementIndex) const
|
|
{
|
|
return (ElementIndex >= 0 && ElementIndex < BaseMaterials.Num()) ? BaseMaterials[ElementIndex] : nullptr;
|
|
}
|
|
|
|
FMaterialRelevance UBaseDynamicMeshComponent::GetMaterialRelevance(ERHIFeatureLevel::Type InFeatureLevel) const
|
|
{
|
|
FMaterialRelevance Result = UMeshComponent::GetMaterialRelevance(InFeatureLevel);
|
|
if (OverrideRenderMaterial)
|
|
{
|
|
Result |= OverrideRenderMaterial->GetRelevance_Concurrent(InFeatureLevel);
|
|
}
|
|
if (SecondaryRenderMaterial)
|
|
{
|
|
Result |= SecondaryRenderMaterial->GetRelevance_Concurrent(InFeatureLevel);
|
|
}
|
|
return Result;
|
|
}
|
|
|
|
void UBaseDynamicMeshComponent::SetMaterial(int32 ElementIndex, UMaterialInterface* Material)
|
|
{
|
|
check(ElementIndex >= 0);
|
|
if (ElementIndex >= BaseMaterials.Num())
|
|
{
|
|
BaseMaterials.SetNum(ElementIndex + 1, false);
|
|
}
|
|
BaseMaterials[ElementIndex] = Material;
|
|
}
|
|
|
|
|
|
void UBaseDynamicMeshComponent::SetNumMaterials(int32 NumMaterials)
|
|
{
|
|
if (BaseMaterials.Num() > NumMaterials)
|
|
{
|
|
// discard extra materials
|
|
BaseMaterials.SetNum(NumMaterials);
|
|
}
|
|
else
|
|
{
|
|
while (NumMaterials < BaseMaterials.Num())
|
|
{
|
|
SetMaterial(NumMaterials, nullptr);
|
|
NumMaterials++;
|
|
}
|
|
}
|
|
}
|
|
|
|
void UBaseDynamicMeshComponent::GetUsedMaterials(TArray<UMaterialInterface*>& OutMaterials, bool bGetDebugMaterials) const
|
|
{
|
|
UMeshComponent::GetUsedMaterials(OutMaterials, bGetDebugMaterials);
|
|
if (OverrideRenderMaterial != nullptr)
|
|
{
|
|
OutMaterials.Add(OverrideRenderMaterial);
|
|
}
|
|
if (SecondaryRenderMaterial != nullptr)
|
|
{
|
|
OutMaterials.Add(SecondaryRenderMaterial);
|
|
}
|
|
}
|
|
|