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 /
  • Help Room /
avatar image
0
Question by AndrewRyan · May 13, 2016 at 10:50 PM · camerarenderingshaderspost processing

How to draw texture on top of everything?

Hello,

I found this really nice shader for drawing screen transitions/wipes behind the UI. What I want to do is draw it on top of everything- even the UI. I tried WaitForEndOfFrame() but that hides the UI because it's getting the current render texture in OnRenderImage()- before the UI is drawn.

So my question is: how do you grab the render texture of the camera after the UI and everything has been drawn, send that to the shader for lerping in an alpha transition, then Gaphics.blit it to the current RT?

This is my current attempt:

 void OnGUI()
     {
         StartCoroutine(RenderOnTop());
     }
 
     IEnumerator RenderOnTop()
     {
         while(true)
         {
             RenderTexture currentRT = RenderTexture.active;
             RenderTexture.active = cam.targetTexture;
             cam.Render();
 
             material.SetColor("_MaskColor", maskColor);
             material.SetFloat("_MaskValue", maskValue);
             material.SetFloat("_MaskSpread", maskSpread);
             material.SetTexture("_MainTex", currentRT);
             material.SetTexture("_MaskTex", maskTexture);
 
             yield return new WaitForEndOfFrame();
 
             Graphics.Blit(currentRT, null, material);
         }
     }

Thanks

P.S. Would UI masks be a more efficient solution?

Comment
Add comment · Show 1
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 AndrewRyan · May 15, 2016 at 09:49 PM 0
Share

I chanced upon a script that saves out a render texture from the main camera, but it renders black for the duration of the transition. Here is my current attempt at grabbing the camera render texture, running the transition, blitting it back then discarding that texture.

     private IEnumerator RenderTex()
     {
         while(transitioning)
         {
             //Wait for graphics to render
             yield return new WaitForEndOfFrame();
 
             //create a render texture
             RenderTexture rt = new RenderTexture(Screen.width, Screen.height, 24);        
 
             //rendertexture
             Camera.main.targetTexture = rt;
             Camera.main.Render();
 
             //assign the rendered texture to rt
             RenderTexture.active = rt;
 
             //pass this rt to the shader
             material.SetColor("_$$anonymous$$askColor", maskColor);
             material.SetFloat("_$$anonymous$$askValue", maskValue);
             material.SetFloat("_$$anonymous$$askSpread", maskSpread);
             material.SetTexture("_$$anonymous$$ainTex", rt);
             material.SetTexture("_$$anonymous$$askTex", maskTexture);
 
             //render the modified source render texture to screen
             Graphics.Blit(rt, null, material);
 
             //reset these to null
             Camera.main.targetTexture = null;
             RenderTexture.active = null; //Added to avoid errors
             //destroy texture
             Destroy(rt);
             yield return null;
         }
     }
 
     //fades
     IEnumerator Fade(bool fadeIn)
     {
         //set this bool to true before calling the coroutine
         transitioning = true;
         //modify render texture in this coroutine
         StartCoroutine(RenderTex());
 
         //create local time var
         float t = 0;
 
         if(fadeIn == false)
         {
             t = 0;
             //play fade out sfx
             if(sfx) sfx.UI("fadeOut");
 
             //while transitioning, add time and assign t to mask value
             while(t < 1.5f)
             {
                 t += Time.deltaTime * Level$$anonymous$$anager.Instance.cameraOptions.fadeSpeed;
                 maskValue = t;
 
                 yield return null;
             }
         }
 
         //fade out
         else
         {
             t = 1.5f;
             //play fade out sfx
             if(sfx) sfx.UI("fadeIn");
 
             //while transitioning, subtract time and assign t to mask value
             while(t > 0)
             {
                 t -= Time.deltaTime * Level$$anonymous$$anager.Instance.cameraOptions.fadeSpeed;
                 maskValue = t;
 
                 yield return null;
             }
         }
 
         //set this bool back to false to stop coroutine while loop
         transitioning = false;
         yield return null;
     }

0 Replies

· Add your reply
  • Sort: 

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

63 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

Related Questions

URP Render Feature missing in final output 0 Answers

How to apply a shader on a part of the scene ? 0 Answers

Post process layer doesnt scale to the camera size 1 Answer

Render Texture not capturing Image Effect Shaders on ARCamera 1 Answer

Blur shader not working after converting render Pipeline 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