How to Alpha Blend a RenderTexture with objects behind it?

I have seen some similar questions asked but none of them seem to have quite this issue. I’m hoping I can get some insight into this. Basically, I’m trying to make a little paint program where a user can select a background and paint over the top of it (not into it). So far I have been able to successfully write to a render texture and apply that to a quad over the top of my background quad. The painting works ok but I can’t seem to figure out the alpha blending. I apologize if this isn’t clear. I’m quite new to shader programming but I’ll try to explain anything that isn’t clear.

So a quick rundown of the process I’m using:

  1. Using Graphics.Blit() I blit a fully transparent texture into the RenderTexture once at the start of the app.

  2. When paint is applied with the mouse I set my RenderTexture as active.

  3. Then I draw the brush textures into RenderTexture using Graphics.DrawTexture() and reset the active render texture to null.

  4. Finally I apply an Unlit shader to blend the RenderTexture with the background image.

I’m using an unlit shader with alpha blending using:

Blend SrcAlpha OneMinusSrcAlpha

I can post the full shader if needed but it’s basically Unity’s standard Transparent Unlit Shader. The problem seems to be that when I blend the RenderTexture I’m getting very low alpha values and the paint appears much more transparent than it should be.

I also tried using AlphaTest:

AlphaTest Greater 0

This has a slightly better result but it seems to produce black outlines around the paint textures which I’m guessing also has to do with the low alpha values.

The thing that puzzles me is that the RenderTexture preview in Unity looks correct. Here is an image of my results and one of the brush I’m using.

Blending

Brush

27107-brush.png

If anyone can provide some insight on how to properly blend a RenderTexture I would greatly appreciate it, thanks!

Check out this answer: Transparent shader: final alpha value wrong - Unity Answers

I was having the same problem. Using a separate blending mode for the alpha as suggested above worked for me!