• 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
Question by jules_fpvr · Aug 23, 2017 at 03:03 PM · rendertextureimage effectsrendertotexture

What is difference between Camera.SetTargetBuffers and setting Camera.targetTexture?

If cam is the Camera component of a camera GameObject and rt is a RenderTexture created with:

 RenderTexture rt = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.ARGB32);

Then, are these three lines all exactly equivalent?

 cam.targetTexture = rt;
 cam.SetTargetBuffers(rt.colorBuffer, rt.depthBuffer);
 cam.SetTargetBuffers(new RenderBuffer[] { rt.colorBuffer }, rt.depthBuffer);

If not, what is the difference?

My code works fine, but when I try to to change the first of these to use SetTargetBuffers my code stops working.

I'm just refactoring code that will shortly be needing MRT (multiple render targets) and I thought I'd test that it still works with one color buffer.

[Edit] In this case not working means that a later stage in the pipeline gets black instead of the expected output when I change from the first line to either of the other two. If there's no expected difference then I guess I need to go through and validate that that is all that's changing between tests and try to create a simpler sample.

Any suggestions as to why this would be?

Thanks

Comment

People who like this

0 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 hexagonius · Aug 26, 2017 at 04:47 AM 0
Share

You answered your first question yourself, if the outcome is different they can't be equal.
What does not working mean?

avatar image sewy · Jun 25, 2021 at 10:37 AM 0
Share

Do you ever make it work? Im facing the same problem - SetTargetBuffers just returns black texture

1 Reply

  • Sort: 
avatar image

Answer by Bunny83 · Aug 26, 2017 at 05:51 AM

The documentation states that at least the first two lines should do the same. However the internal declaraion looks, well, strange:

 public void SetTargetBuffers(RenderBuffer colorBuffer, RenderBuffer depthBuffer)
 {
     this.SetTargetBuffersImpl(out colorBuffer, out depthBuffer);
 }
 
 public void SetTargetBuffers(RenderBuffer[] colorBuffer, RenderBuffer depthBuffer)
 {
     this.SetTargetBuffersMRTImpl(colorBuffer, out depthBuffer);
 }

What's strange is that in the single RenderBuffer version both are "out" parameters. This might not be a problem as "SetTargetBuffersImpl" is a native method so the "out" restriction most likely do not apply. Though we can't be sure about that. From a pure managed point of view the implementation as it stands makes no sense. Since out and ref parameters are actual pointers to the variables (not managed references) it probably shouldn't matter.

Comment

People who like this

0 Show 1 · 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 jules_fpvr · Aug 27, 2017 at 08:09 AM 0
Share

That does look odd - the wrapper hides the out, so my RenderTarget can't be affected.

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

72 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

Related Questions

How to specify a depthSlice of Camera's targetTexture? 1 Answer

Graphics.Blit() results in empty RenderTexture 1 Answer

Using custom RenderTexture in ImageEffects. 1 Answer

RenderTexture clears after Blit 0 Answers

Is it possible to resize the destination rendertarget? 1 Answer


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