Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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
1
Question by Kuura · Jan 03, 2016 at 09:13 AM · shaderrendertexturerender textureclearblit

Prevent Render Texture clearing

In a nutshell, How can I prevent RenderTextures from being cleared after every frame?

I have a script that writes high intensity values to a render texture and I want to do an image effect with this over multiple frames while constantly drawing more to it; kinda like a camera with no clear flags. The problem with this is that Unity is damn dedicated to clear the RenderTexture on every frame with the camera content. Is it possible to prevent this somehow or make a workaround?

Here's my simple script for reference.

Unity 5.3.1p1

 using UnityEngine;
 
 [RequireComponent(typeof(Camera))]
 public class TemporalTest : MonoBehaviour {
 
     public Shader temporalTestShader;
     public RenderTexture rt;
     public Material temporalMaterial;
 
     void Start () {
         rt = new RenderTexture(Screen.width, Screen.height, 0);
         temporalMaterial = new Material(temporalTestShader);
     }
 
     void OnRenderImage(RenderTexture source, RenderTexture destination) {

         // rt gets filled correctly here
         // but it's cleared every frame for no reason causing nuclear headaches

         temporalMaterial.SetTexture("_TemporalMap", rt);
         Graphics.Blit(source, rt, temporalMaterial, 0);
     }
 }
 
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
2
Best Answer

Answer by Kuura · Jan 04, 2016 at 01:25 PM

Ok, after hours of debugging I found out that it was the Blit function that is clearing the rendertexture and not unity in between OnRenderImage calls.

The problem was that you can't do

 mat.SetTexture("something", sometex);
 Blit(A, B, mat); // Add A to "something" in shader and save to some result B

and expect it to write the result nicely to B. Instead you have to use temporary rendertextures and do

 mat.SetTexture("something", sometex);
 RenderTexture temp = RenderTexture.GetTemporary(...);
 Blit(A, temp, mat); // Add A to "something", save to temp
 Blit(temp, B); // Copy temp to some result texture B
 RenderTexture.Release(temp);

I don't know why it has to be done this way or why can't I use B straight as a result and so on but at least it works.

Comment
Add comment · 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 TocaSimon · Dec 05, 2019 at 09:57 AM 0
Share

Thank you!

We had this exact problem. We're usually are developing on OSX but we had a $$anonymous$$m member joining on Windows and a feature related to this did not work at all. Your solution solved everything. You are my hero for the day!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Blit problem 2 Answers

Blit shader to RenderTexture results in solid black 0 Answers

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

How to use Graphics.Blit with custom input textures 3 Answers

In Unity 2D how can I make a shader aware of the Z coordinate (depth) of the object it is about to draw over? 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