May 18, 2013

ScreenPos align for RenderTarget

Sometimes we need to project texture from object to screen space. Default ScreenPos node in UDK has option "screen aligned", and it seemed to work ok - texture is really aligned to screen.

But in some cases it doesn't work as we want. For example, when you're using SceneCaptureActor which duplicates position and location of main camera (I use this trick to draw transparent ocean). By default render target is square, let's say that your screen resolution is 1280 x 720, the result is:


It's ok only when the camera's pitch is zero. More pitch - more deformation.

The simplest way to fix it is to set resolution of render target with the same dimensions as screen resoliton has. It's rude, and can't be used for production if you expect user will change the resolution.

Solution is very simple. We should use only part of texture we need. I've prepared simple hlsl code to be used in Custom node:


It'll work only with square render targets! I think that key idea is clear, so if you have to use non-square RTs, you can modify it on your own.


It looks pretty good, and we don't scare screen resolution changes now.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.