自定義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()