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
1
Question by Patapom · Oct 04, 2011 at 12:32 PM · rendertextureunexpectedclear

Unwanted render texture clear

Hi !

I have a RenderEffect attached to a camera with a RenderTexture that I fill up with a nice red color in OnPreRender(), but when I display it in OnRenderImage(), the texture is cleared to black...

Does Unity perform unsolicited clears of textures ? Is there a catch about some internal recycle mechanism of render textures I'm not aware of ? Did I make a mistake at some point ?

Thanks for your time.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Patapom · Sep 22, 2012 at 12:48 PM

Hello again,

I finally found the actual bug with that issue. It was so twisted that it made me report the bug wrongly.

So the actual bug is this :
1] Clear a RenderTexture to RED in OnPreRender()
2] Display it in OnRenderImage(), the texture is cleared to some other value

Why does it do this ?
=> Because I forgot to reset the RenderTexture.active state when I left my OnPreRender() so Unity goes on with its pipeline and clears the RenderTexture.active with the default solid color you chose for your camera ! (or skybox or whatever)

You could think it's my fault, that people at Unity were nice and offered the opportunity for the user to specify the RenderTexture where the scene will be rendered but it's really a bug since after the clear occurs, the scene is rendered to the real RenderTexture the scene should render to.

It means the Unity pipeline is faulty and goes like this :

 1] Call user's OnPreRender()
  => User changes RenderTexture.active and returns
 2] Clear RenderTexture.active with solid color/sky box/whatever
  (**without** bothering to reset the RenderTexture.active to the actual scene RenderTexture, so it clears YOUR RenderTexture)
 3] Sets the actual scene RenderTexture (finally)
 4] Renders the scene
 5] Call user's OnRenderImage()
  => At this point, re-using the last RenderTexture set in OnPreRender() yields a wrong result

For now, I go around the bug by doing this :

 void  OnPreRender()
 {
    RenderTexture Old = RenderTexture.active;  // Backup
    (...)
    Do some stuff with RenderTextures
    (...)
    RenderTexture.active = Old; // Restore. **Don't** set RenderTexture.active to null or your scene's RenderTexture won't be cleared !
 }

Hope that helps !

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

2 People are following this question.

avatar image avatar image

Related Questions

Prevent Render Texture clearing 1 Answer

CommandBuffer.ClearRenderTarget(true, false, Color.clear, 1f) produces black depth texture? 0 Answers

OnRenderImage disable MRT(Multiple Render Targets)? 0 Answers

My Render Texture is not rendering World Space Canvas UI objects 0 Answers

glReadPixels from a RenderTexture 3 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