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).
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):
And if i "oneminus" them it behaves like a pencil (black pencil on transparent background):
(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.:
Anyone knows where i can fit an opacity blending formula ?
Follow this question
Once you sign in you will be able to subscribe for any updates here