I’ve been playing with materials, shaders, render targets and what-could-be-done, and I’m facing something I can’t quite revolve my head around. To reduce the scope of what’s happening with my project I extraced the culprit, to no avail as the issue was still there. So I’m turning to you to find some help.
So as a minimal issue, here’s the deal:
I have two render targets, both RGBA16f, that’s my two render buffers. Call them Current and Temp.
I then have two materials, one is adding a constant float parameter to the red channel of the input texture, the other one does a simple copy. Both use the Unlit shading model and send data to emissive, with “allow negative emissive values” checked.
This is because both materials are then used by an actor in my world, which is responsible for calling boths shaders to render on the two render targets. As you would imagine, these are interleaved, so on each tick we :
- Take Temp as input, add X to Temp.r, store this value in Current
- Take Current as input and copy to Temp
So effectively, with initially black render targets, I get increasing red value in both.
This works for a moment, but the issue begins to show after some time depending on the amount I choose to add on each update.
eg: If I set X (the amount to add each update) to 1.0f; my red channel stops at 2048 and never gets past it. As it is fully dynamic I can increase X to 2 while simulating, red will slowly rise to 4096 and stop there. So there’s at least one hint, it seems to be linear.
But why on earth would it stop at such values ? That’s a simple add, and clearly we are not overflowing (maxValue = 65535).
Here’s the file if you want to test by yourself, or have a better look :
Just open the attached map, and you can run the simulation and change the added amount on BP_ShaderCycle actor. It will show as a sphere, vertically displaced by the amount of red read in our rendered texture. There is also a parameter on the MaterialInstance associated with said mesh, HeightThreshold, which is useful to manually read the computed red value, turning the sphere from red to green when it goes past it.
By default there, with Amount set to 0.5f, the red sphere should rise up to 1024 units and stop (and turn green with the threshold set).
What am I missing guys ? I hope you can help !