Download

ScreenPosition and SceneColor

I’m working on a material to simulate water distortion for orthographic cameras and I have succesfully managed to blend two noises together to modify the ScreenPosition UVs and pass them to SceneColor. The result is pretty good, but when an object with the material moves near the right or bottom edge of the view I get a weird white color. I suspect the white spots come from UVs referring an area outside SceneColor.

Stripping down the material, it all comes to this:

As you can see, I just plug ScreenPosition with added arbitrary coordinates into SceneColor and the latter into emissive color.
I tried clipping between 0 and 1, dividing by screen width and a lot more to understand how ScreenPosition outputs its data but to no avail. Everything seems perfectly in order until SceneColor comes around.
The coordinates I can input are also puzzling. First 0.1 and 0.3 don’t seem to relate to my view size in any way and second, when I input negative values…

… I don’t get the white effect at all.
I don’t really know what to try at this point. Is there any way I can avoid this behavior mirroring or, better, clamping the position of ScreenColor I’m going to read from?



Frame.SceneTextureMinMax.zw;


I use this code at custom node to get size of scene color texture. Then you can just clamp uv’s to that.

Thanks a lot, that really did the trick. I’ll expand my material a bit more and then I’ll share it.

Is there a list where I can look for codes like this one that could help me later?

I tried googling it but nothing came up except a mention in another thread here and a couple of chinese pages.

I found that by random googling. Be careful with updates. This kind undocumented uniforms keep to change their names or absence too often.

Quick update: in UE4.13, the code is


View.SceneTextureMinMax.zw;

Just a minor note that this artifact should only happen in the editor and not in a standalone game due to the way the editor allocates extra size in the buffer for other viewports etc. So you can fix it using the clamp but if you skip the clamp you will save some instructions.

Also there is an actual node that gives you the screen size so you don’t need the custom node. It is called “View Property”. You place it and then select the property “View Size” and it should be the same as the code above but it will be future proof.