How do I render canvas to texture with proper transparency?
I have a UI Canvas which is being rendered to a RenderTexture.
This Canvas contains semi-transparent elements that live on top of opaque elements.
When I render the Canvas to the texture, the texture's alpha channel is using the alpha of whatever is drawn on top, in this case, the semi-transparent element's alpha value.
This is resulting in parts of the texture being semi-transparent in places where there are opaque elements present.
Is there a way to have the texture's alpha be based from the whole hierarchy of elements, not just the top one?
Version: 2018.4.2f1
Edit
A simple example.
In the below setup I have a blue transparent square on top of a red opaque square on top of some opaque text. (These all live within a Canvas).
When I tell the camera that is drawing these elements to render them to a render texture, the place in the middle where they all overlap has a transparency level equal to that of the blue square.
I would expect that part of the texture to have no transparency.
But what component sdo you have in the aprent? please post some screenshots of inspector
I have added an example to better describe the situation.
Attached are screenshots of the hierarchy and the inspector for all objects present in the scene.
The RenderTexture that results from this setup can be found above.
Answer by jbolton42 · Oct 07, 2019 at 09:39 AM
I found a bug report for this issue. It has been marked as By Design. https://issuetracker.unity3d.com/issues/world-space-canvas-rendered-to-a-rendertexture-has-improper-alpha-values
Answer by Clement_Shimizu · May 28, 2020 at 06:05 PM
You need to add the following line to the UI shaders you are using. BlendOp Add, Max
https://gitlab.com/drclementshimizu/unity3d-canvas-rendertotexture-bug