Material to RenderTarget Alpha Help

Hi

Long story short I’m getting some weird looking results in the Alpha Channel of my Render Target that I used to render a material to with my Blueprint.
I searched far and wide for answers, but came short of a solution :frowning:

So I set up a quick test to show what I’ve been getting and what I was… expecting to get :stuck_out_tongue:

So here is my material. In this case I rendered two sets of gradients - essentially the Red and Green Channels should be identical to the Blue and Alpha Channels - I used the lerp node to invert the alpha just in case, but I essentially got the same results with the 1-x node.


Here is the Blueprint I used to render out the material.


And here is the final result.


All looks as expected until we compare the Green Channel below (the red and blue channels are identical as expected)


And the Alpha Channel


As you can see despite the same values going into the channels (okay the alpha was inverted) I get some very different results?

The values seem to have shifted in the alpha channel, so could there be some way or restoring them to what they should be for example when we read the texture in a new material?
I tried using different Render Target format, but no dice Alpha still looks different compared to my Blue Channel…
Did I mess up something when I inverted the Alpha or is this an engine thing t(his is on UE4.23)?
Sooo has anyone else encountered this?
Anyone know a fix?

Any help will be suuuper appreciated!

So I did some more digging and it looks like the problem is not with the Render Target or the Blueprint, but with the material that is being rendered,
I decided to have a look at some of the debug values going in and sure enough I noticed some strange things… namely my alpha values were immediately different to my green channel values.
I know because of the setup that the numbers are a mess, but the red and blue channels show an identical mess - so it looks like something happened to the values as soon as they were appended to the Alpha Channel?


So I tested both float 2 values that went into the float 4 for my own sanity

So I also did some digging around and a similar issue seems to happen with textures when packed into the Alpha channel… so much so that you’d need to make some math adjustments while eyeballing it (and I did test the mentioned fix of adding a Power of 0.55 no dice… and also another post that suggested a Power of 2.2 - that was really wrong)
https://answers.unrealengine.com/questions/50468/view.html

If anyone is wondering why such precision in needed, my main reason is Compute Shaders - being able to pack more data into an RGBA image and then read it properly can go pretty far in optimizing performance - but yah getting accurate packed textures would be nice too I guess :stuck_out_tongue:

So this is starting to look more and more like a bug unless I am doing something wrong on my end - if someone can recreate this on their end (or better yet do this and get the correct results) please let me know!

Just a little update. If you’ve encountered this and are losing your mind - this appears to be a bug which you can now track here: Unreal Engine Issues and Bug Tracker (UE-100558)

The result you got is totally expected and correct operation of AlphaComposite blend mode. Not sure why you’d think it is a bug.

I’ll admit I’m not 100% familiar with the AlphaComposite blend mode, but I first noticed the issue when using it so that’s where I started with the initial post.
Later tests in the material editor showed the same results regardless of the bled mode - textures and gradients appended in the alpha channel always look a bit off, they have their values shifted a bit?
Like in the final image you can see that the green channel from the textures coordinate node is appended in both the greed and alpha channels, but the debug view shows different values for it in both in contrast when the red channel is appended to the red and blue channels it shows the same values. It looks like it might be some compression thing but I haven’t really managed to find any info on it.
Any ideas if this is normal?

Alpha component value, displayed through debug material function, is located lower than green value, and therefore will have higher value of G component of texcoord.

Ahhh $#!%@ Where were you a few months ago!?
Yup it do be like that! So my second post is all wrong then :stuck_out_tongue:

While you are here… any idea how I can get a blueprint to draw a material with an opacity texture onto a render correctly? From what I’ve seen so far you have to use the Alpha Composite blend mode or else the alpha will not be rendered at all, but as you see when used it, gradients and values come a bit off.
You mentioned that the value change is “expected” - how so? And is there any way to correct or account for it?
I looked around quite a bit for info on this so any help will be suuuuper appreciated!

Set material domain to post process, enable alpha output. Note, that it will still limit your opacity to 0 - 1 range.

2 Likes