# UE5.5 Global Shader : SvPositionToTranslatedWorld not work

**URL:** <https://forums.unrealengine.com/t/ue5-5-global-shader-svpositiontotranslatedworld-not-work/2279877>\
**Category:** C++\
**Tags:** unreal-engine, shader, CPP, question, Global-Shaders\
**Created:** [January 16, 2025, 8:52am UTC](https://forums.unrealengine.com/t/ue5-5-global-shader-svpositiontotranslatedworld-not-work/2279877 "2025-01-16T08:52:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![IAmNoBody2we](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IAmNoBody2we](https://forums.unrealengine.com/u/IAmNoBody2we)\
**Post date:** [January 16, 2025, 8:52am UTC](https://forums.unrealengine.com/t/ue5-5-global-shader-svpositiontotranslatedworld-not-work/2279877/1 "2025-01-16T08:52:51Z")

</div>

Unreal Engine Version 5.5

I am developing a global shader injected into the beginning of PostProcess phase in rendering pipeline.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/8/b/88b8aa96f7e8a912472a983479ae76b181c717ae.png)

In `/Engine/Shaders/Common.usf`, there are three methods

- `SvPositionToScreenPosition`
- `SvPositionToTranslatedWorld`
- `SvPositionToResolvedTranslatedWorld`

```hlsl
void MainPS( float4 SvPosition : SV_POSITION, out float4 OutColor : SV_Target0)
{
    //float4 ScreenPos = SvPositionToScreenPosition(SvPosition); // [-1, 1]
    float3 WorldPos = SvPositionToTranslatedWorld(SvPosition);

    if (isnan(WorldPos.x) || isinf(WorldPos.y))
    {
        OutColor = float4(1.0, 0.0, 0.0, 1.0); // Red indicates invalid values
    }
    else
    {
        OutColor = float4(WorldPos.x / 100000, WorldPos.y / 100000, WorldPos.z / 100000, 1.0);
    }        
}

```

From my test, `SvPositionToScreenPosition` works fine, while `SvPositionToTranslatedWorld` and `SvPositionToResolvedTranslatedWorld` produce invalid values. I can see the whole screen is red.

By looking in the source code of `SvPositionToTranslatedWorld`, it internally depends on `View`

```hlsl
// Used for post process shaders which don't need to resolve the view	
float3 SvPositionToTranslatedWorld(float4 SvPosition)
{
	float4 HomWorldPos = mul(float4(SvPosition.xyz, 1), View.SVPositionToTranslatedWorld);

	return HomWorldPos.xyz / HomWorldPos.w;
}

```

So I added `View` in the shader, and set it with `InView.ViewUniformBuffer` as below. That does not work.

```cpp
class FOcclusionFreeShaderPS : public FGlobalShader {
public:
    DECLARE_SHADER_TYPE(FOcclusionFreeShaderPS, Global, );
    SHADER_USE_PARAMETER_STRUCT(FOcclusionFreeShaderPS, FGlobalShader);

    BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
        SHADER_PARAMETER_STRUCT_REF(FViewUniformShaderParameters, View)
        SHADER_PARAMETER_RDG_TEXTURE(Texture2D, InputTexture)
	    SHADER_PARAMETER_SAMPLER(SamplerState, InputSampler)
        RENDER_TARGET_BINDING_SLOTS()
    END_SHADER_PARAMETER_STRUCT()
};

void FSplitSceneViewExtension::PrePostProcessPass_RenderThread(FRDGBuilder& GraphBuilder, const FSceneView& InView, const FPostProcessingInputs& Inputs)
{
	if( InView.PlayerIndex == 0 )
	{
		const FIntRect ViewPort = static_cast<const FViewInfo&>(InView).ViewRect;
		FGlobalShaderMap* GlobalShaderMap = GetGlobalShaderMap(GMaxRHIFeatureLevel);	//GetShader for certain feature level

		RDG_EVENT_SCOPE(GraphBuilder, "OcclusionFree");

		FRHISamplerState* PointClampSampler = TStaticSamplerState<SF_Point, AM_Clamp, AM_Clamp, AM_Clamp>::GetRHI();
		Inputs.Validate();

		TShaderMapRef<FOcclusionFreeShaderPS> GlobalShaderPS(GlobalShaderMap);
		FOcclusionFreeShaderPS::FParameters* GlobalShaderParameters = GraphBuilder.AllocParameters<FOcclusionFreeShaderPS::FParameters>();

		// ...
		GlobalShaderParameters->View = InView.ViewUniformBuffer;
		GlobalShaderParameters->RenderTargets[0] = FRenderTargetBinding(SceneColor.Texture, ERenderTargetLoadAction::ELoad); //(FRDGTexture, ELoadAction)

		FPixelShaderUtils::AddFullscreenPass( GraphBuilder, GlobalShaderMap, FRDGEventName(TEXT("FOcclusionFreeShaderPS")), GlobalShaderPS, GlobalShaderParameters, ViewPort);
	}
}

```

Please where is the problem? how to solve it?

---

<div class="post-metadata">

**Author:** ![IAmNoBody2we](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IAmNoBody2we](https://forums.unrealengine.com/u/IAmNoBody2we)\
**Post date:** [January 18, 2025, 7:49am UTC](https://forums.unrealengine.com/t/ue5-5-global-shader-svpositiontotranslatedworld-not-work/2279877/2 "2025-01-18T07:49:14Z")

</div>

I found the reason, it is because `SvPosition .z` is not filled correctly, I have to manually set its z from SceneDepth texture. Maybe I am missing something so that the `z` is not filled in my PS Shader

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [February 17, 2025, 7:49am UTC](https://forums.unrealengine.com/t/ue5-5-global-shader-svpositiontotranslatedworld-not-work/2279877/3 "2025-02-17T07:49:56Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
