Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by voidcoder · Aug 19, 2017 at 08:46 PM · cameratexturerendertexturealpha-channelrender to texture

Why Camera clear color alpha channel is ignored?

Dear community

I'm struggling to get camera to use alpha channel of clear color. It looks to me it doesn't matter what you set clear color alpha value to, unity will still use 255 instead.

This is primarily for render to texture. I want to use an off-screen render camera to render something to a texture. I need the background of my render texture to remain transparent when this render texture is rendered back into the main scene (a quad with simple material referencing my render texture).

These are my steps so far:

  1. Create a RenderTexture asset, 2D, ARGB32

  2. Create a Camera and set it to render to my RenderTexture

  3. Set camera Clear Flags to Solid Color

  4. Set Background color to say RGBA(255,0,0,0), note alpha=0

Now if I check my render texture in inspector it is showing solid red background as if my clear color was RGBA(255,0,0,255). The non-trasparent background makes it impossible to use as an overlay on top of some other content :(

Any ideas please?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FortisVenaliter · Aug 24, 2017 at 05:03 PM 0
Share

Deferred or Forward pass rendering?

I think this only works with Forward.

avatar image voidcoder · Aug 24, 2017 at 07:19 PM 0
Share

No difference. Both deferred and forward rendering produce the same result with alpha channel completely ignored :(

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by JonPQ · Aug 24, 2017 at 10:44 PM

I had to do this before... my solution was to not render transparent, but to render it magenta... the old school color for transparency. Then I ran a script to search through the texture2d pixels... and swap out the pixels for my desired transparent color.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image voidcoder · Aug 26, 2017 at 09:19 PM 0
Share

Thanks. Technically this might work but will be extremely expensive I'm afraid.

I wonder whats the reason behind this limitation? At the lower level all graphics APIs support 4 channel clear color. Why on earth Unity would suppress that?

avatar image JonPQ voidcoder · Aug 28, 2017 at 07:03 PM 0
Share

probably if the camera is clearing the screen. there is no reason to have any transparency, as there can't possibly be anything behind it. They could add it as an option if you are doing a render to texture.... that would be nice. For me... performance was not an issue with the magenta trick, as I was running it as an editor script, to generate sprites that looked exactly the same as the models in scene... for nice LOD

avatar image JonPQ voidcoder · Aug 28, 2017 at 07:06 PM 0
Share

another option you might employ is same deal... render background as magenta.... Which is still fast. then render the sprite or object with a custom shader... that replaces magenta with transparent alpha in pixel shader. Though I wouldn't call that an efficient shader. Depends if you need to do this on-the-fly every frame or not, for which option is best.

avatar image
0

Answer by DomeCreator · Feb 24, 2021 at 03:14 PM

Hi guys, @voidcoder I'm facing the same problem for others reasons but I was wondering you'll find a way to do that without killing perfs ?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

106 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rendering a Pygame surface in Unity 0 Answers

Capture RenderTexture pixels multiple times in one frame? 1 Answer

Multiple Render Texture and Ordering 0 Answers

Render texture and shader issues 0 Answers

Save image from camera with post processing. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges