OK, I think I solved one problem but now have another.
I figured out the problem with creating the array – there is some delay in ReadLinearColorPixels modifying the OutputBuffer, so the OutputBuffer needs to be a reference to an array that is outside the scope and won’t get destroyed once the reference is no longer in scope. Fine.
But now, I have an issue with writing the color array into the fog render target, and it relates to two problems with Zhi_Kang_Shao’s code for writing the array into the render target. First, he has the following line:
FMemory::Memcpy(MipData, PixelData.GetData(), DataSize);
However, PixelData is undefined, so I get an error.
Second, although he defines InputBuffer, the InputBuffer reference never gets used in his code. I suspect that he’s missing a line of code somewhere that converts the InputBuffer into whatever “PixelData” is, but I don’t know what class PixelData is supposed to be or how to convert the InputBuffer to that. But maybe I’m wrong about that. Either way, PixelData is undefined, and InputBuffer doesn’t get used.
So, apparently “PixelData” should be “InputBuffer.” I finally got it sorted out. Time to put this in my real game rather than just the test project I set up to play with this plugin.
One important note to anyone implementing a save feature on the fog of war: The code posted by the developer relies on reading and writing to a referenced array of FLinearColors. The functions that do that work in the rendering thread, so that process is going to lag your game thread. If you are saving and loading in the game thread, you are going to be using that array before the rendering thread modifies it, so you will be saving or loading an empty array. The solution I came up with is to call FlushRenderingCommands() after you try to fill the array but before you do anything with that array. That will pause the game thread while the rendering thread catches up. Maybe there’s a better solution, but that one seemed to work for me.
Overall, this is a great plugin; thanks!