Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
5
Question by raja-bala · Sep 29, 2014 at 07:01 PM · rendertextureblittargettexture

Blit camera targetTexture to screen

My main camera has a script attached to it that sets its targetTexture to mainRT. Whatever the camera sees is rendered to it.

Then, I blend another RT particlesRT via Graphics.Blit(particlesRT, mainRT, blendMaterial); in OnPostRender()

I want to blit the resulting mainRT to the screen. Going by Unity's documentation, I thought using null for the destination render texture would do it, i.e., Graphics.Blit(mainRT, null as RenderTexture);

I tried using it in both OnPostRender and OnRenderImage. I end up with a blank screen in both cases. When I comment out OnRenderImage, I see that things are blended nicely into mainRT. But the blit to screen doesn't work. When OnRenderImage exists (i.e., the function isn't commented), chaos happens, and mainRT seems to have been cleared.

Can I not blit a camera's render texture to screen?

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

2 Replies

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

Answer by raja-bala · Oct 04, 2014 at 12:39 AM

After some experimentation, I ended up not using OnRenderImage() (completely removed the function)

Instead I did the following:

 RenderTexture mainSceneRT;
 RenderTexture rayMarchRT;
 ...
 void OnPreRender() {
     camera.targetTexture = mainSceneRT;
     // this ensures that w/e the camera sees is rendered to the above RT
 }
 
 void OnPostrender() {
     ... // render to secondary render target
     Graphics.Blit(rayMarchRT, mainSceneRT, matDepthBlend);

     // You have to set target texture to null for the Blit below to work
     camera.targetTexture = null;
     Graphics.Blit(mainSceneRT, null as RenderTexture);
 }
Comment
Add comment · Show 10 · 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 Helical · Oct 14, 2014 at 03:55 PM 0
Share

what did you set mainSceneRT? do you have pro?

avatar image raja-bala · Mar 23, 2015 at 08:39 AM 0
Share

this is uber late, but yes, i have pro (4.*). In 5.0+, RenderTexture is part of the personal edition

avatar image byrne · Jun 08, 2015 at 09:25 AM 0
Share

No matter how i try it, I can't get this code to work. 1. I assume mainSceneRT is a fullscreen rendertexture, and 'camera' is the main camera. 2. where is the source for ray$$anonymous$$archRT? It suddenly just gets dropped into a function without any initialisation. I found this part confusing. 3. The way I understand the code, the OP is taking the main camera's output, blending it with ray$$anonymous$$archRT, disabling the targettexture, and then using Graphics.Blit to render the final mainSceneRT. 4. With this understanding I am unable to set up the scene to work. The blit just does not work and it just shows what the main camera originally sees.

avatar image Mikeysee · Jul 09, 2015 at 09:16 AM 0
Share

I too have spent hours struggling with this, can you give a simple demo project?

avatar image raja-bala · Jul 10, 2015 at 08:01 AM 0
Share

Umm, the solution posted above was supposed to be it :) Do message or link to your question and I'll see if i can help.

Show more comments
avatar image
0

Answer by hearstzhang · Jun 19, 2019 at 06:18 AM

I‘ve seen your answer, but if you attach another script with OnRenderImage, everything becomes noisy again.

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

30 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

Related Questions

Can a rendertexture be placed on top of an image? (Minimap help) 0 Answers

How to alter/modify a RenderTexture with a shader,How can I modify/"post process" a RenderTexture using a shader 0 Answers

dynamic hole in layer / texture / camera 0 Answers

Where to Graphics.Blit()? 1 Answer

Need Help Getting RenderTexture & Graphics.Blit Working: Boosting Mobile Performance 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