Download

Write to arbitrary pixels in a frame buffer, or render target

I understand why this might not be possible, but it looks like some other engines support this concept and I can’t find any info on how to do it in Unreal or via HLSL.

Basically, is it possible to set a pixel other than the current pixel in a post process? Is there anywhere outside of a post process where this might be possible?

This is a classic gather vs scatter problem.

Basically what you are wanting to do is “Scatter” a value from A to B, where B is some location other than the current pixel. GPUs are notoriously terrible at that and there is really no way to do it in UE4 that I am aware of.

The alternate technique is ‘gather’ which means that you are still in effect doing A to B, but you achieve it by starting at B and instead backtracking to A and using the information “gathered” at that point to decide what to actually do with B. This is why things like screen space reflections require multiple steps, they need to ‘search’ for the correct intersection with linear search.

So you need to write a basic tracer of some kind that can find the A point, whatever that may be in your case. If you know the exact distance and location you are looking for, you simply offset to that position as your starting position before, and you apply the inverse to backtrack for the gather. Its much easier than it sounds.

http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter31.html

They have a nice blurb on scatter vs gather here:

To do a scatter approach I believe you will need to set up a custom buffer in c++ for now.

For what its worth, even when writing gather operations, I often find it useful to flip the logic in my head and think of it like a scatter operation. All you really have to do is flip the signs (ie positive offset becomes negative) and the two can be inverted so that you don’t have to think in the backwards space.

This also kind of relates to simulations like advection where you typically backtrack to advect rather than go forward in time.