# DFAO and Shift word origin

**URL:** <https://forums.unrealengine.com/t/dfao-and-shift-word-origin/421578>\
**Category:** Rendering\
**Tags:** world-position-offse, distance-field-ambie, unreal-engine, Rendering, question\
**Created:** [April 2, 2018, 7:05am UTC](https://forums.unrealengine.com/t/dfao-and-shift-word-origin/421578 "2018-04-02T07:05:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![fenglangfaxue](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@fenglangfaxue](https://forums.unrealengine.com/u/fenglangfaxue)\
**Post date:** [April 2, 2018, 7:05am UTC](https://forums.unrealengine.com/t/dfao-and-shift-word-origin/421578/1 "2018-04-02T07:05:51Z")

</div>

Our team are developing a multiplayer online battle royale game. We use both World Origin Shift and Distance Field Ambient Occlusion.When we use SetWorldOriginLocation function to shift the world, the Actor and physics both work correctly, but the DFAO is very weird as shown in the following image.

 ![235922-screenshot00006.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/7/6/0760f87f16b8f860e905e7b9b7b58bc5a6f8989a.jpeg)

 ![235926-screenshot00003.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/8/6/f86e8d2486f6a89537c5725c86c4275777a3b53a.jpeg)

The right AO texture shoud be the following:

 ![235927-screenshot00004.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/d/6/9d6c2cd69d0bfe2b386d96eb7f27df2d6c480a4d.jpeg)

After eject, I found the Distance Field Ambient Occlusion Texture is not correct, not match the world’s primitives.  
After some further investigation, I have found that the UStaticMeshComponent’s Distance Field not be updated in the Global Distance Field. The Global Distance Field does nothing when the world origin be shifted.

I fix it by modify some Rendering files below.

in the class FSceneInterface of SceneInterface.h :

```
  add: virtual void UpdatePrimitiveDistanceFieldSceneData_GameThread(UPrimitiveComponent* Primitive) {};

```

in the class FScene of ScenePrivate.h:

```
add:  
        virtual void UpdatePrimitiveDistanceFieldSceneData_GameThread(UPrimitiveComponent* Primitive) override;
         void UpdatePrimitiveDistanceField_RenderThread(FPrimitiveSceneProxy* PrimitiveSceneProxy);

```

in the RenderScene.cpp:

```
 add :
  void FScene::UpdatePrimitiveDistanceFieldSceneData_GameThread(UPrimitiveComponent* Primitive)
{	
           if（Primitive->SceneProxy）
           {
	    FScene* Scene = this;
	    ENQUEUE_RENDER_COMMAND(UpdateDistanceFieldCommand)(
		[Scene, Primitive](FRHICommandListImmediate& RHICmdList)
		{
			FScopeCycleCounter Context(Primitive->SceneProxy->GetStatId());
			Scene->UpdatePrimitiveDistanceField_RenderThread(Primitive->SceneProxy);
		});
         }
}

void FScene::UpdatePrimitiveDistanceField_RenderThread(FPrimitiveSceneProxy* PrimitiveSceneProxy)
{
	 DistanceFieldSceneData.UpdatePrimitive(PrimitiveSceneProxy->GetPrimitiveSceneInfo());
 }

```

in the class UPrimitiveComponent of PrimitiveComponent.h：

```
add: virtual void ApplyWorldOffset(const FVector& InOffset, bool bWorldShift) override;

```

in the PrimitiveComponent.cpp

```
add:  	
    void UPrimitiveComponent::ApplyWorldOffset(const FVector& InOffset, bool bWorldShift)
    {
    	Super::ApplyWorldOffset(InOffset, bWorldShift);
    	if (SceneProxy)
    	{
    		GetWorld()->Scene->UpdatePrimitiveDistanceFieldSceneData_GameThread(this);
    	}
    } 

```

That fix the problem.  
Though I fix by myself, but I think offset the Global Distance Field Volume Texture in  
FScene::ApplyWorldOffset\_RenderThread(FVector InOffset) function must be elegant and efficient.

Our game website : [http://en.zogame.com.cn/](http://en.zogame.com.cn/)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_942e8e52](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_942e8e52](https://forums.unrealengine.com/u/anonymous_user_942e8e52)\
**Post date:** [April 20, 2018, 3:43pm UTC](https://forums.unrealengine.com/t/dfao-and-shift-word-origin/421578/2 "2018-04-20T15:43:46Z")

</div>

Thank you for this report, we are currently tracking this at: [Unreal Engine Issues and Bug Tracker (UE-55375)](https://issues.unrealengine.com/issue/UE-55375)

The workaround suggested is similar to yours above:

“FPrimitiveSceneInfo::ApplyWorldOffset should call DistanceFieldSceneData.UpdatePrimitive(this); That will cause ProcessPrimitiveUpdate to be called again for that object, fetching the new offsetted proxy bounds and uploading them to the DistanceFieldSceneData (GPU representation of the scene)”

---

<div class="post-metadata">

**Author:** ![Mathias\_TML](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mathias\_TML](https://forums.unrealengine.com/u/Mathias_TML)\
**Post date:** [October 25, 2019, 10:55am UTC](https://forums.unrealengine.com/t/dfao-and-shift-word-origin/421578/3 "2019-10-25T10:55:09Z")

</div>

Hi,  
we experience the same issue in our project. Your fix is great, simple and is working. Unfortunately, this causes hitches with ~400ms duration while doing origin rebasing. Do you have the same performance issue? Do you have a different solution in the meanwhile?

---

<div class="post-metadata">

**Author:** ![gozu](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gozu/32/869945_2.png) [@gozu](https://forums.unrealengine.com/u/gozu)\
**Post date:** [October 26, 2019, 10:16pm UTC](https://forums.unrealengine.com/t/dfao-and-shift-word-origin/421578/4 "2019-10-26T22:16:06Z")

</div>

Also curious on this. stumbled back on this thread after looking into some issues with ray traced distance field shadows, which seem to be bugged in 4.23.1 when you rebase 😕 (very early days looking into it though…)

---

<div class="post-metadata">

**Author:** ![gozu](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gozu/32/869945_2.png) [@gozu](https://forums.unrealengine.com/u/gozu)\
**Post date:** [October 26, 2019, 11:23pm UTC](https://forums.unrealengine.com/t/dfao-and-shift-word-origin/421578/5 "2019-10-26T23:23:24Z")

</div>

Woo. i was able to reproduce a bug with Distance Field Shadows moving when you rebase, i don’t remember this in 4.23, but it happens in 4.23.1 now. I have submitted a bug report (just incase anyone else here reads this…)

---

<div class="post-metadata">

**Author:** ![Mathias\_TML](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mathias\_TML](https://forums.unrealengine.com/u/Mathias_TML)\
**Post date:** [October 28, 2019, 9:15am UTC](https://forums.unrealengine.com/t/dfao-and-shift-word-origin/421578/6 "2019-10-28T09:15:50Z")

</div>

We are working in with 4.22.3. I think this bug was never fixed.

---

<div class="post-metadata">

**Author:** ![Mathias\_TML](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mathias\_TML](https://forums.unrealengine.com/u/Mathias_TML)\
**Post date:** [December 10, 2019, 11:11am UTC](https://forums.unrealengine.com/t/dfao-and-shift-word-origin/421578/7 "2019-12-10T11:11:48Z")

</div>

I’ve implemented a fix for this problem here:

[https://github.com/EpicGames/UnrealEngine/pull/6424](https://github.com/EpicGames/UnrealEngine/pull/6424)

Maybe this helps
