Agrarsense
|
#include <InstancedRenderer.h>
Public Member Functions | |
AInstancedRenderer (const FObjectInitializer &ObjectInitializer) | |
bool | AddActorToInstancedRendering (AInstancedActor *InstancedActor) |
void | RemoveInstance (int32 ComponentIndex, int32 InstanceNumber) |
void | AddOrRemoveActorFromAutomaticTransformUpdates (bool Add, AInstancedActor *InstancedActor) |
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) |
Private Member Functions | |
void | BeginPlay () override |
void | Tick (float DeltaTime) override |
void | EndPlay (const EEndPlayReason::Type EndPlayReason) override |
void | OnGraphicsSettingsChanged (FGlobalGraphicsSettings GraphicsSettings) |
void | OnWeatherParametersChanged (FWeatherParameters WeatherParameters) |
bool | AreTransformsEqual (const FTransform &TransformA, const FTransform &TransformB) const |
void | UpdateInstancedActors () |
int32 | FindOrAddUniqueMesh (UStaticMeshComponent *StaticMeshComponent, AInstancedActor *InstancedActor) |
Private Attributes | |
TArray< FInstanceEntry > | InstanceEntries |
int32 | WorldPositionOffsetDistance = 30000 |
std::vector< FInstancedActorData > | InstancedActorsToUpdate |
FWeatherParameters | CurrentWeatherParameters |
int32 | TotalInstanceCount |
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 UInstancedStaticMeshComponent.
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.
Note. Mesh material(s) need to have bUsedWithInstancedStaticMeshes set to True to work with UInstancedStaticMeshComponent.
Definition at line 64 of file InstancedRenderer.h.
AInstancedRenderer::AInstancedRenderer | ( | const FObjectInitializer & | ObjectInitializer | ) |
Definition at line 18 of file InstancedRenderer.cpp.
bool AInstancedRenderer::AddActorToInstancedRendering | ( | AInstancedActor * | InstancedActor | ) |
Definition at line 162 of file InstancedRenderer.cpp.
References FInstancedActorData::Actor, AddOrRemoveActorFromAutomaticTransformUpdates(), FindOrAddUniqueMesh(), AInstancedActor::GetStaticMeshComponent(), AInstancedActor::InstanceAdded(), InstanceEntries, TotalInstanceCount, and AInstancedActor::UpdateTransformAutomatically().
Referenced by AInstancedActor::AddToInstancedRendering().
void AInstancedRenderer::AddOrRemoveActorFromAutomaticTransformUpdates | ( | bool | Add, |
AInstancedActor * | InstancedActor | ||
) |
Adds or removes an instanced actor from automatic transform updates.
Add | True to add the actor to automatic transform updates, false to remove. |
InstancedActor | Pointer to the instanced actor being added or removed. |
Definition at line 381 of file InstancedRenderer.cpp.
References FInstancedActorData::Actor, InstancedActorsToUpdate, and AInstancedActor::UpdatePreviousTransform().
Referenced by AddActorToInstancedRendering(), and AInstancedActor::SetUpdateTransformAutomatically().
|
private |
Definition at line 472 of file InstancedRenderer.cpp.
Referenced by UpdateInstancedActors().
|
overrideprivate |
Definition at line 25 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 598 of file InstancedRenderer.cpp.
References InstanceEntries.
|
overrideprivate |
Definition at line 76 of file InstancedRenderer.cpp.
References UAgrarsenseStatics::GetAgrarsenseSettings(), UAgrarsenseStatics::GetWeatherActor(), Instance, InstancedActorsToUpdate, InstanceEntries, OnGraphicsSettingsChanged(), UAgrarsenseSettings::OnGraphicsSettingsChanged, AWeather::OnWeatherChanged, and OnWeatherParametersChanged().
|
private |
Definition at line 238 of file InstancedRenderer.cpp.
References FInstanceEntry::AllowWorldPositionOffsetDisable, CurrentWeatherParameters, AInstancedActor::GetAllowWorldPositionOffsetDisable(), AInstancedActor::GetInstanceEndCullDistance(), AInstancedActor::GetInstanceStartCullDistance(), AInstancedActor::HasAlternativeMaterial(), FInstanceEntry::InstancedStaticMeshComponent, InstanceEntries, FInstanceEntry::InstanceEntryIndex, FInstanceEntry::Materials, FInstanceEntry::Mesh, FInstanceEntry::MeshName, FWeatherParameters::WindIntensity, and WorldPositionOffsetDistance.
Referenced by AddActorToInstancedRendering().
|
inline |
Definition at line 135 of file InstancedRenderer.h.
|
inline |
Definition at line 115 of file InstancedRenderer.h.
|
inline |
Definition at line 125 of file InstancedRenderer.h.
|
inline |
Definition at line 105 of file InstancedRenderer.h.
void AInstancedRenderer::LogInfo | ( | ) | const |
Definition at line 69 of file InstancedRenderer.cpp.
References InstanceEntries, and TotalInstanceCount.
Referenced by BeginPlay().
|
private |
Definition at line 527 of file InstancedRenderer.cpp.
References FGlobalGraphicsSettings::FoliageShadowCacheInvalidationBehaviour, SetShadowCacheBehaviour(), SetWorldPositionOffsetDistance(), and FGlobalGraphicsSettings::WorldPositionOffsetDistance.
Referenced by BeginPlay(), and EndPlay().
|
private |
Definition at line 533 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 428 of file InstancedRenderer.cpp.
References FInstanceEntry::InstancedStaticMeshComponent, InstanceEntries, TotalInstanceCount, and AInstancedActor::UpdateIndex().
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 509 of file InstancedRenderer.cpp.
References FInstanceEntry::InstancedStaticMeshComponent, and InstanceEntries.
void AInstancedRenderer::SetInstancedRendering | ( | bool | ShouldRender | ) |
Definition at line 493 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 546 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 586 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 575 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 557 of file InstancedRenderer.cpp.
References InstanceEntries, and WorldPositionOffsetDistance.
Referenced by OnGraphicsSettingsChanged().
|
overrideprivate |
Definition at line 125 of file InstancedRenderer.cpp.
References UpdateInstancedActors().
|
private |
Definition at line 130 of file InstancedRenderer.cpp.
References FInstancedActorData::Actor, AreTransformsEqual(), AInstancedActor::GetComponentIndex(), AInstancedActor::GetInstanceIndex(), AInstancedActor::GetPreviousTransform(), InstancedActorsToUpdate, UpdateInstanceTransform(), and AInstancedActor::UpdatePreviousTransform().
Referenced by Tick().
void AInstancedRenderer::UpdateInstanceTransform | ( | int32 | ComponentIndex, |
int32 | InstanceNumber, | ||
const FTransform & | NewTransform | ||
) |
Definition at line 413 of file InstancedRenderer.cpp.
References FInstanceEntry::InstancedStaticMeshComponent, and InstanceEntries.
Referenced by UpdateInstancedActors(), and AInstancedActor::UpdateTransformPosition().
|
private |
Definition at line 238 of file InstancedRenderer.h.
Referenced by BeginPlay(), FindOrAddUniqueMesh(), and OnWeatherParametersChanged().
|
staticprivate |
Definition at line 197 of file InstancedRenderer.h.
Referenced by BeginPlay(), and EndPlay().
|
private |
Definition at line 236 of file InstancedRenderer.h.
Referenced by AddOrRemoveActorFromAutomaticTransformUpdates(), EndPlay(), and UpdateInstancedActors().
|
private |
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 229 of file InstancedRenderer.h.
Referenced by AddActorToInstancedRendering(), DebugMaterialImpact(), EndPlay(), FindOrAddUniqueMesh(), LogInfo(), RemoveInstance(), SetComponentIndexVisibility(), SetInstancedRendering(), SetRenderCustomDepth(), SetRenderWorldPositionOffet(), SetShadowCacheBehaviour(), SetWorldPositionOffsetDistance(), and UpdateInstanceTransform().
|
private |
Definition at line 242 of file InstancedRenderer.h.
Referenced by SetInstancedRendering().
|
private |
Definition at line 244 of file InstancedRenderer.h.
|
private |
Definition at line 240 of file InstancedRenderer.h.
Referenced by AddActorToInstancedRendering(), LogInfo(), and RemoveInstance().
|
private |
World Position Offset (WPO) render distance in cm
Definition at line 234 of file InstancedRenderer.h.
Referenced by BeginPlay(), FindOrAddUniqueMesh(), and SetWorldPositionOffsetDistance().