自定义UPrimitiveComponent时,通过PDI进行绘制时发现会发生视锥剔除(frustum-culling)的问题
查询原因是没生成Bounds的问题.(UE是通过边缘检测进行视锥剔除的)
可通过重写UPrimitiveComponent::CalcBounds模拟一个Bounds
Ref:
unreal 的剔除原理:
https://docs.unrealengine.com/4.27/en-US/RenderingAndGraphics/VisibilityCulling/
e.g:
UCLASS() class XXX_API UCanvasGridProxy final : public UPrimitiveComponent { GENERATED_BODY() public: UCanvasGridProxy() { PrimaryComponentTick.bCanEverTick = false; } private: virtual FBoxSphereBounds CalcBounds(const FTransform& LocalToWorld) const override { FBoxSphereBounds b ; b.Origin = FVector(0); b.SphereRadius = 1000; b.BoxExtent.Set(1000, 1000, 1000); //b.SphereRadius = 1000; return b; } virtual FPrimitiveSceneProxy* CreateSceneProxy() override { return new FCanvasGridProxy(this); } };
如果要限制FPrimitiveSceneProxy的遮挡剔除可以重写FPrimitiveSceneProxy::CanBeOccluded,自己计算遮挡剔除的运算逻辑
virtual bool CanBeOccluded() const override { return false; }//这里直接均不进行遮挡剔除
Note:CalcBounds的调用由UE完成,需要更新calcBounds函数时请调用函数:
UActorComponent::MarkRenderStateDirty()