Download

Worldspace -> Screen space, View.ScreenPositionScaleBias broken?

I’m working on an effect that requires me to transform a given “worldspace” coordinate (not just “Absolute World Position”, but any arbitrary coordinate) into a coordinate with which to sample a node like “Scene Color” or “Screen Texture”.

I’m using the following code:



float4 screenPos = mul(float4(WorldPosition,1), View.WorldToClip);
float2 screenUV = screenPos.xy/screenPos.w;
screenUV *= View.ScreenPositionScaleBias.xy;
screenUV += View.ScreenPositionScaleBias.wz;
return screenUV;


This code produces correct results in UE4.18, but fails in 4.25.

The problem seems to be in the difference between the Screen size and the Buffer size.

In editor, the buffer can be bigger than the actual viewport.
The *screenPos *is in coordinates relative to the viewport, but I need the screenUV to be in the size of the Buffer, in order to sample Scene Color or Screen Texture.


screenUV *= View.ScreenPositionScaleBias.xy;
screenUV += View.ScreenPositionScaleBias.wz;

This part used to take care of that, but doesn’t anymore in the latest version. Instead, the effect only works correctly.

Any ideas?