x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

[4.13] How to write alpha channel when rendering to RenderTarget from Blueprints

When rendering to RenderTarget in a blueprint I need to write all 4 channels of the render target. There's no problem in writing color values (rgb), but I can't find the way to write directly to the alpha channel of the render target. Value in alpha channel is not related to color, but will be used as the mask in subsequent calls.

Product Version: UE 4.13
Tags:
more ▼

asked Sep 06 '16 at 10:19 AM in Rendering

avatar image

devast3d
242 15 19 47

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

After inspecting source code I found that there's not correct way to make it. However there's workaround if one wants to output all 4 channels to the empty render target. Here are the steps:

  • In a blueprint: clear render target to (0, 0, 0, 1) color

  • Make you material Unlit, set blend mode to AlphaComposite

  • Route RGB to Emissive color

  • Route inverse of our Alpha to Opacity color

This way you will have RGBA written into render target.

It works because of blend state descripion. Following code is taken from the sources:

 case BLEND_AlphaComposite:
     // Blend with existing scene color. New color is already pre-multiplied by alpha.
     RHICmdList.SetBlendState(TStaticBlendState<CW_RGBA,
         BO_Add, BF_One, BF_InverseSourceAlpha, 
         BO_Add,  BF_Zero, BF_InverseSourceAlpha>::GetRHI());
     break;

Since Dst.RGB is black it will not affect the result. However Alpha equation is SrcAlpha*Zero+Dst*InverseSrcAlpha, so by inversing Opacity ouput and clearing render target alpha to 1 you will have what you need.

It's shame we don't have the ability to specify custom blend state in a material...

more ▼

answered Sep 13 '16 at 11:38 AM

avatar image

devast3d
242 15 19 47

avatar image RVillani Oct 21 '17 at 07:51 PM

In 4.17 it worked by:

  • Setting Draw material to AlphaComposite blend mode;

  • Using standard Alpha (not inverted)

  • Setting the mesh/widget material that display the RenderTexture to use inverted alpha output from RenderTexture (OneMinus node)

  • Clear RenderTexture to (0, 0, 0, 1)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question