How to achieve Render texture with correct alpha channel

What im trying to do:

  1. Created second camera
  2. Created render texture
  3. Set render texture to second camera
  4. Created plane
  5. Create material with render texture from second camera
  6. Set material on plane
  7. Set the layer mask on camera to render only some effects

So i want to achieve transparent texture only with some effects on it.
But i cant. Alpha channel of the render rexture always 0.

How to achieve correct alpha values in render texture?

You need to make sure of three things:

  • Your second camera needs to use a clear colour with the alpha value you want in empty spaces.
  • The objects rendered by your second camera need to use shaders that write appropriate alpha values
  • The material for your plane needs to support blending so that the alpha values from the render texture are used appropriately as transparency.
2 Likes
  1. done
  2. I cant make that shader. Seems im mising smth. Can you give me simple example?
  3. done

What i need to modify in that shader so it will write to alpha?

Shader "Mobile/Particles/Alpha Blended1" {
Properties {
    _MainTex ("Particle Texture", 2D) = "white" {}
}

Category {
    Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    Blend SrcAlpha OneMinusSrcAlpha
    Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) }
   
   
    BindChannels {
        Bind "Color", color
        Bind "Vertex", vertex
        Bind "TexCoord", texcoord
    }
   
    SubShader {
        Pass {
            SetTexture [_MainTex] {
                combine texture * primary
            }
        }
    }
}
}

You should add “Color RGBA” to allow write alpha to frame buffer

1 Like

That shader should write alpha to the target. Are you using textures with alpha? Do they appear correctly when you view them in your regular camera?

It would be ColorMask, and RGBA is the default, so there’s not need to add ColorMask RGBA.

Made all from scratch and it finally work. With shader above. Thanks to all.

How did it excatly work? Can you share please?

What part of that shader specifically makes it write alpha into the output texture ?
I’m trying to do the same thing but render varying alpha into the render texture…
if I use pragma surface surf Lambert alpha:fade then the whole render texture has 0 alpha.
But if I render the same object in the scene, it has graduated alpha over the whole object specified by the alpha on the 3d object’s texture

if I use pragma surface surf Lambert then the object renders solid diffuse and renders ok as a RawImage it has 1 alpha where my object is and 0 around it. but no graduated alpha across my object.

How can I make the alpha on the texture get rendered out into the render texture please ?

Life saver.

You need to disable HDR in the camera to show a transparent background.

2 Likes

Thanks! This was it for me. Also, on URP unchecking the Post Processing on camera helps.

1 Like