Agrarsense
|
#include <InstancedRenderer.h>
Public Member Functions | |
AInstancedRenderer (const FObjectInitializer &ObjectInitializer) | |
bool | AddActorToInstancedRendering (AInstancedActor *InstancedActor) |
void | RemoveInstance (int32 ComponentIndex, int32 InstanceNumber) |
void | UpdateInstanceTransform (int32 ComponentIndex, int32 InstanceNumber, const FTransform &NewTransform) |
bool | IsRendering () const |
int32 | GetTotalInstanceCount () const |
int32 | GetUniqueInstancesCount () const |
TArray< FInstanceEntry > | GetInstanceEntries () const |
void | SetInstancedRendering (bool ShouldRender) |
void | SetComponentIndexVisibility (int32 Index, bool Visible) |
void | SetRenderCustomDepth (bool Enabled) |
void | SetWorldPositionOffsetDistance (int32 NewWPODistance) |
void | SetShadowCacheBehaviour (EShadowCacheInvalidationBehavior ShadowCacheInvalidationBehaviour) |
void | SetRenderWorldPositionOffet (bool RenderWPO) |
void | LogInfo () const |
void | DebugMaterialImpact (bool SetUnrealDefaultMaterial) |
void | ToggleProxyMesh () |
void | SpawnAllInstancesBackActors () |
bool | SpawnInstanceBackToActor (UInstancedStaticMeshComponent *ISM, int32 Index) |
Static Public Member Functions | |
static AInstancedRenderer * | Get () |
Protected Attributes | |
TArray< FInstanceEntry > | InstanceEntries |
TArray< UInstancedStaticMeshComponent * > | InstancesStaticMeshComponents |
int32 | TotalInstanceCount = 0 |
Private Member Functions | |
virtual void | BeginPlay () override |
virtual void | EndPlay (const EEndPlayReason::Type EndPlayReason) override |
void | OnGraphicsSettingsChanged (FGlobalGraphicsSettings GraphicsSettings) |
void | OnWeatherParametersChanged (FWeatherParameters WeatherParameters) |
int32 | FindOrAddUniqueMesh (UStaticMeshComponent *StaticMeshComponent, AInstancedActor *InstancedActor) |
Private Attributes | |
TWeakObjectPtr< UStaticMesh > | ProxyMesh |
int32 | WorldPositionOffsetDistance = 30000 |
FWeatherParameters | CurrentWeatherParameters |
bool | Rendering = true |
bool | RenderingWPO = true |
Static Private Attributes | |
static AInstancedRenderer * | Instance = nullptr |
This Actor is responsible for rendering all added unique mesh entries with unique materials efficiently with UInstancedStaticMeshComponents.
The way this works is by creating blueprint based on AInstancedActor in Unreal Editor, setup the desired mesh and material in the blueprint and placing them in the level in any way. Then at runtime (AInstancedActor BeginPlay), its Mesh and Material is added to this Renderer.
Or you can setup AInstancedActor based actors in your level and then go to BP_InstancedRenderer Actor and click "AddExistingActorsToRenderer" button to turn AInstancedActors into BP_InstancedRenderer ISM instances. This reduces the amount of Actors in the level and should speed up loading times.
AInstancedActors marked as "TreeActor" can be turned back into regular Actor at runtime when vehicle gets close.
Note. Mesh material(s) need to have bUsedWithInstancedStaticMeshes set to True to work with UInstancedStaticMeshComponent.
Definition at line 75 of file InstancedRenderer.h.
AInstancedRenderer::AInstancedRenderer | ( | const FObjectInitializer & | ObjectInitializer | ) |
Definition at line 19 of file InstancedRenderer.cpp.
References ProxyMesh.
bool AInstancedRenderer::AddActorToInstancedRendering | ( | AInstancedActor * | InstancedActor | ) |
Definition at line 129 of file InstancedRenderer.cpp.
References FindOrAddUniqueMesh(), AInstancedActor::GetStaticMeshComponent(), AInstancedActor::InstanceAdded(), InstanceEntries, and TotalInstanceCount.
Referenced by AInstancedActor::AddToInstancedRendering().
|
overrideprivatevirtual |
Definition at line 33 of file InstancedRenderer.cpp.
References CurrentWeatherParameters, Destroy, UAgrarsenseStatics::GetAgrarsenseSettings(), AWeather::GetCurrentWeather(), UAgrarsenseStatics::GetWeatherActor(), UAgrarsenseSettings::GetWorldPositionOffsetRenderDistance(), Instance, LogInfo(), OnGraphicsSettingsChanged(), UAgrarsenseSettings::OnGraphicsSettingsChanged, AWeather::OnWeatherChanged, OnWeatherParametersChanged(), and WorldPositionOffsetDistance.
void AInstancedRenderer::DebugMaterialImpact | ( | bool | SetUnrealDefaultMaterial | ) |
Definition at line 481 of file InstancedRenderer.cpp.
References InstanceEntries.
|
overrideprivatevirtual |
Definition at line 83 of file InstancedRenderer.cpp.
References UAgrarsenseStatics::GetAgrarsenseSettings(), UAgrarsenseStatics::GetWeatherActor(), Instance, InstanceEntries, OnGraphicsSettingsChanged(), UAgrarsenseSettings::OnGraphicsSettingsChanged, AWeather::OnWeatherChanged, and OnWeatherParametersChanged().
|
private |
Definition at line 193 of file InstancedRenderer.cpp.
References FInstanceEntry::ActorClass, FInstanceEntry::AllowWorldPositionOffsetDisable, CurrentWeatherParameters, FInstanceEntry::CustomDepthStencilValue, AInstancedActor::GetAllowWorldPositionOffsetDisable(), AInstancedActor::GetInstanceEndCullDistance(), AInstancedActor::GetInstanceStartCullDistance(), AInstancedActor::HasAlternativeMaterial(), FInstanceEntry::InstancedStaticMeshComponent, InstanceEntries, FInstanceEntry::InstanceEntryIndex, FInstanceEntry::IsTree, AInstancedActor::IsTreeActor(), FInstanceEntry::Materials, FInstanceEntry::Mesh, FWeatherParameters::WindIntensity, and WorldPositionOffsetDistance.
Referenced by AddActorToInstancedRendering().
|
inlinestatic |
Definition at line 212 of file InstancedRenderer.h.
|
inline |
Definition at line 140 of file InstancedRenderer.h.
|
inline |
Definition at line 120 of file InstancedRenderer.h.
|
inline |
Definition at line 130 of file InstancedRenderer.h.
|
inline |
Definition at line 110 of file InstancedRenderer.h.
void AInstancedRenderer::LogInfo | ( | ) | const |
Definition at line 76 of file InstancedRenderer.cpp.
References InstanceEntries, and TotalInstanceCount.
Referenced by BeginPlay().
|
private |
Definition at line 410 of file InstancedRenderer.cpp.
References FGlobalGraphicsSettings::FoliageShadowCacheInvalidationBehaviour, SetShadowCacheBehaviour(), SetWorldPositionOffsetDistance(), and FGlobalGraphicsSettings::WorldPositionOffsetDistance.
Referenced by BeginPlay(), and EndPlay().
|
private |
Definition at line 416 of file InstancedRenderer.cpp.
References CurrentWeatherParameters, SetRenderWorldPositionOffet(), and FWeatherParameters::WindIntensity.
Referenced by BeginPlay(), and EndPlay().
void AInstancedRenderer::RemoveInstance | ( | int32 | ComponentIndex, |
int32 | InstanceNumber | ||
) |
Definition at line 359 of file InstancedRenderer.cpp.
References FInstanceEntry::InstancedStaticMeshComponent, InstanceEntries, and TotalInstanceCount.
Referenced by AInstancedActor::RemoveFromInstancedRendering().
void AInstancedRenderer::SetComponentIndexVisibility | ( | int32 | Index, |
bool | Visible | ||
) |
Set the visibility of a specific UInstancedStaticMeshComponent at the given index. Debugging purposes.
Index | The index of the UInstancedStaticMeshComponent to modify. |
Visible | Whether to make the component visible (true) or hidden (false). |
Definition at line 392 of file InstancedRenderer.cpp.
References FInstanceEntry::InstancedStaticMeshComponent, and InstanceEntries.
void AInstancedRenderer::SetInstancedRendering | ( | bool | ShouldRender | ) |
Definition at line 376 of file InstancedRenderer.cpp.
References InstanceEntries, and Rendering.
Referenced by UAgrarsenseSettings::SetInstancedRenderingVisibility().
void AInstancedRenderer::SetRenderCustomDepth | ( | bool | Enabled | ) |
Sets whether the custom depth rendering is enabled or disabled.
Enabled | True to enable custom depth rendering, false to disable. |
Definition at line 429 of file InstancedRenderer.cpp.
References InstanceEntries.
void AInstancedRenderer::SetRenderWorldPositionOffet | ( | bool | RenderWPO | ) |
Sets whether the World Position Offset (WPO) rendering is enabled or disabled.
RenderWPO | True to enable World Position Offset rendering, false to disable. |
Definition at line 469 of file InstancedRenderer.cpp.
References InstanceEntries.
Referenced by OnWeatherParametersChanged().
void AInstancedRenderer::SetShadowCacheBehaviour | ( | EShadowCacheInvalidationBehavior | ShadowCacheInvalidationBehaviour | ) |
Sets the behavior for shadow cache invalidation. Default Rigid.
ShadowCacheInvalidationBehaviour | The new behavior for shadow cache invalidation. |
Definition at line 458 of file InstancedRenderer.cpp.
References InstanceEntries.
Referenced by OnGraphicsSettingsChanged().
void AInstancedRenderer::SetWorldPositionOffsetDistance | ( | int32 | NewWPODistance | ) |
Sets the distance for the World Position Offset (WPO) effect.
NewWPODistance | The new distance for the World Position Offset. |
Definition at line 440 of file InstancedRenderer.cpp.
References InstanceEntries, and WorldPositionOffsetDistance.
Referenced by OnGraphicsSettingsChanged().
void AInstancedRenderer::SpawnAllInstancesBackActors | ( | ) |
Definition at line 544 of file InstancedRenderer.cpp.
References InstanceEntries, and Transform.
bool AInstancedRenderer::SpawnInstanceBackToActor | ( | UInstancedStaticMeshComponent * | ISM, |
int32 | Index | ||
) |
Definition at line 594 of file InstancedRenderer.cpp.
References FInstanceEntry::ActorClass, AInstancedActor::AddToInstancedRenderer, FInstanceEntry::InstancedStaticMeshComponent, and InstanceEntries.
void AInstancedRenderer::ToggleProxyMesh | ( | ) |
Definition at line 520 of file InstancedRenderer.cpp.
References InstanceEntries, and ProxyMesh.
void AInstancedRenderer::UpdateInstanceTransform | ( | int32 | ComponentIndex, |
int32 | InstanceNumber, | ||
const FTransform & | NewTransform | ||
) |
Definition at line 344 of file InstancedRenderer.cpp.
References FInstanceEntry::InstancedStaticMeshComponent, and InstanceEntries.
Referenced by AInstancedActor::UpdateTransformPosition().
|
private |
Definition at line 259 of file InstancedRenderer.h.
Referenced by BeginPlay(), FindOrAddUniqueMesh(), and OnWeatherParametersChanged().
|
staticprivate |
Definition at line 236 of file InstancedRenderer.h.
Referenced by BeginPlay(), and EndPlay().
|
protected |
Array containing instance entries for each unique mesh and material combination. Each entry represents an instance of a mesh with associated actors and properties.
Definition at line 224 of file InstancedRenderer.h.
Referenced by AddActorToInstancedRendering(), DebugMaterialImpact(), EndPlay(), FindOrAddUniqueMesh(), LogInfo(), RemoveInstance(), SetComponentIndexVisibility(), SetInstancedRendering(), SetRenderCustomDepth(), SetRenderWorldPositionOffet(), SetShadowCacheBehaviour(), SetWorldPositionOffsetDistance(), SpawnAllInstancesBackActors(), SpawnInstanceBackToActor(), ToggleProxyMesh(), and UpdateInstanceTransform().
|
protected |
Definition at line 227 of file InstancedRenderer.h.
|
private |
Definition at line 234 of file InstancedRenderer.h.
Referenced by AInstancedRenderer(), and ToggleProxyMesh().
|
private |
Definition at line 261 of file InstancedRenderer.h.
Referenced by SetInstancedRendering().
|
private |
Definition at line 263 of file InstancedRenderer.h.
|
protected |
Definition at line 230 of file InstancedRenderer.h.
Referenced by AddActorToInstancedRendering(), LogInfo(), and RemoveInstance().
|
private |
World Position Offset (WPO) render distance in cm
Definition at line 257 of file InstancedRenderer.h.
Referenced by BeginPlay(), FindOrAddUniqueMesh(), and SetWorldPositionOffsetDistance().