DenisM
August 5, 2014, 9:22am
1
What im trying to do:
Created second camera
Created render texture
Set render texture to second camera
Created plane
Create material with render texture from second camera
Set material on plane
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
DenisM
August 5, 2014, 4:10pm
3
done
I cant make that shader. Seems im mising smth. Can you give me simple example?
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.
DenisM
August 6, 2014, 3:10pm
6
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 ?
You need to disable HDR in the camera to show a transparent background.
2 Likes
AliBuck
December 27, 2022, 11:37am
11
Thanks! This was it for me. Also, on URP unchecking the Post Processing on camera helps.
1 Like