Add culling for decals (via DrawMinScreenSize property)

This commit is contained in:
Wojtek Figat
2021-01-18 15:53:15 +01:00
parent d19c31555b
commit ef240ce986
2 changed files with 17 additions and 1 deletions

View File

@@ -7,6 +7,7 @@
#include "Engine/Level/Scene/SceneRendering.h"
#include "Engine/Graphics/RenderView.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderTools.h"
Decal::Decal(const SpawnParams& params)
: Actor(params)
@@ -66,6 +67,13 @@ void Decal::Draw(RenderContext& renderContext)
Material->IsLoaded() &&
Material->IsDecal())
{
const auto lodView = (renderContext.LodProxyView ? renderContext.LodProxyView : &renderContext.View);
const float screenRadiusSquared = RenderTools::ComputeBoundsScreenRadiusSquared(_sphere.Center, _sphere.Radius, *lodView) * renderContext.View.ModelLODDistanceFactorSqrt;
// Check if decal is being culled
if (Math::Square(DrawMinScreenSize * 0.5f) > screenRadiusSquared)
return;
renderContext.List->Decals.Add(this);
}
}
@@ -80,6 +88,7 @@ void Decal::Serialize(SerializeStream& stream, const void* otherObj)
SERIALIZE(Material);
SERIALIZE_MEMBER(Size, _size);
SERIALIZE(SortOrder);
SERIALIZE(DrawMinScreenSize);
}
void Decal::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
@@ -90,6 +99,7 @@ void Decal::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
DESERIALIZE(Material);
DESERIALIZE_MEMBER(Size, _size);
DESERIALIZE(SortOrder);
DESERIALIZE(DrawMinScreenSize);
}
bool Decal::IntersectsItself(const Ray& ray, float& distance, Vector3& normal)

View File

@@ -30,9 +30,15 @@ public:
/// <summary>
/// The decal rendering order. The higher values are render later (on top).
/// </summary>
API_FIELD(Attributes="EditorOrder(20), DefaultValue(0), EditorDisplay(\"Decal\")")
API_FIELD(Attributes="EditorOrder(20), EditorDisplay(\"Decal\")")
int32 SortOrder = 0;
/// <summary>
/// The minimum screen size for the decal drawing. If the decal size on the screen is smaller than this value then decal will be culled. Set it to higher value to make culling more aggressive.
/// </summary>
API_FIELD(Attributes="EditorOrder(30), EditorDisplay(\"Decal\")")
float DrawMinScreenSize = 0.02f;
/// <summary>
/// Gets the decal bounds size (in local space).
/// </summary>