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"

Manually blending opacities in rendertarget ?


I'm trying to use rendertarget to make a mini paint program in my game.

I'd want to be able to draw and erase.

The way i do that is by setting a transparent rendertarget (FLinearColor(0., 0., 0., 0.)) and drawing a pencil texture on top of it.

I would expect that mecanism to function as a pencil when the pencil texture is opaque and as an eraser when the pencil texture is transparent (alpha=0).

Here's the setup for the 2 materials (rendertarget material = background, pencil material = pencil).

alt text

The problem is that the blending of the opaticies is additive and not multiplicative.

So if i don't "oneminus" the opacity of the rendertarget, it behaves as a fog or war (eraser only = transparent pencil on black background):

alt text

And if i "oneminus" them it behaves like a pencil (black pencil on transparent background):

alt text

(On those 2 screenshots, the whole mechanism is superimposed to a regular texture of a map which is a simple texture on a different mesh and is never modified).

But i couldn't find a way for this mechanism to work both as pencil and eraser by modifying only the pencil material.

As you can see in the pencil material on the right of the first screenshot, i tried to use negative opacity (and allowing negative emissive colors), but with no success.

I need to obtain both results by modifying only the pencil material and not the rendertarget material.

I saw this post here, which is very clear, and the formulas given by the staff member are simple and clear: https://answers.unrealengine.com/questions/465100/draw-material-to-render-target-node-has-inverted-a.html?sort=oldest

My problem is that i don't know where to use them. Where should manually blend (multiply) the opacities for 2 different material ? The DrawMaterial function doesn't seem to offer that possibility.

Just for the sake of completeness, here's my very simple code to draw, which is exactly what would be done in a blueprint.:

 UKismetRenderingLibrary::BeginDrawCanvasToRenderTarget(GetWorld(), WhiteboardRenderTargetCanvas, WhiteboardCanvas, WhiteboardSize, WhiteboardContext);
 WhiteboardCanvas->K2_DrawMaterial(PencilMaterialInstance, TexturePos, TextureSize * NewTextureScale, FVector2D(0.f, 0.f));
 UKismetRenderingLibrary::EndDrawCanvasToRenderTarget(GetWorld(), WhiteboardContext);

Anyone knows where i can fit an opacity blending formula ?



Product Version: UE 4.21
01.jpg (53.4 kB)
02.jpg (46.9 kB)
03.jpg (51.5 kB)
more ▼

asked Apr 20 '19 at 10:29 AM in Rendering

avatar image

870 75 93 363

avatar image uced Apr 23 '19 at 08:03 AM

I also created a question in the forum, i'll update here if i get some help from there.


avatar image uced Apr 28 '19 at 09:11 AM

I have opened a bug report in the hope to get some help, i'll keep this thread informed.

(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