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"

Drawing Alpha channel to a TextureRenderTarget2D?

I'm currently working on a system which uses the Canvas system to draw other assets (such as text, textures, etc) onto a TextureRenderTarget2D.

These elements are then overlayed on top of another texture in a material according to the rendered texture's alpha channel.

However, Canvas' handling of alpha channels appears to be pretty much completely random.

I was able to get basic stuff running by setting the ClearColor of the TextureRenderTarget2D to be completely translucent, which gives me a translucent base to start drawing to.

When I draw text to the canvas via an FCanvasTextItem, by default, the text is drawn to the color channels of the TextureRenderTarget2D, but it leaves the Alpha unchanged from the base transparency despite the color of the CanvasTextItem set to be opaque. However, I was able to get this to draw to the alpha properly by setting the CanvasTextItem's BlendMode to ESimpleElementBlendMode::SE_BLEND_Opaque. However, this has the side effect of doing weird things to the color channels: the text's color is drawn to the texture as just a rectangular blob, though only the letters are visible since only the actual font is drawn to the alpha channel. So that's okay, I guess.

But when it comes to drawing other CanvasItems to the Canvas (specifically, FCanvasBoxItems and FCanvasLineItems) nothing I do seems to make the items draw to the TextureRenderTarget2D's alpha channel. The color of the items are completely opaque, and I've tried going through every single option for ESimpleElementBlendMode with no effect.

I know the drawing is otherwise working, since I can see the boxes and lines in the color channels of the texture. But without them setting the alpha, they're invisible.

There's a bit of suspicious code in the line drawing function: // Ensure the line isn't masked out. Some legacy code relies on Color.A being ignored. FLinearColor OpaqueColor(Color); OpaqueColor.A = 1;

But given that it's setting the alpha to entirely opaque, I don't see why this would cause problems, but may indicate some weirdness around the handling of transparency elsewhere. Does anyone know what the deal is with CanvasItems and transparency? Is there a correct way of doing this?

Product Version: UE 4.15
more ▼

asked Apr 27 '17 at 10:49 PM in C++ Programming

avatar image

629 26 28 55

avatar image TheBunyip Jul 11 '17 at 09:07 PM

I'm having very similar problems. I'm trying to use an additive blend material to write to a render target using a canvas but nothing I do will allow me to write to the alpha channel in the material.

avatar image TheBunyip Jul 11 '17 at 09:10 PM

Did you manage to resolve the issue in any way?

avatar image Teiwaz Jul 11 '17 at 10:32 PM

Not really. I ended up bailing on slate and moving to UMG. UMG's FWidgetRenderer renders to the alpha channel correctly, but you need a full widget instead of just slate elements.

avatar image TheBunyip Jul 12 '17 at 07:46 AM

Darn it. Thanks for the reply and glad to hear you solved your problem.

avatar image Mr GEL Jun 20 '18 at 04:29 PM

I had a similar problem. I Used SE_BLEND_AlphaBlend from the DrawTile implentation in Canvas.cpp. I copied the implementation and used it in my code with a few minor adjustment. Works like a charm. My overlapped textures on rendertarget are properly blended, and the result with the background is correct as well. No weird stuff as i was getting before. Like where the two textures were overlapping and supposed to be blending, there was just a block of transparency with the background shining through.

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

0 answers: sort voted first
Be the first one to answer this question
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