Search Unity

Clear Render Texture

Discussion in 'Scripting' started by metervara, Jul 27, 2007.

  1. metervara

    metervara

    Joined:
    Jun 15, 2006
    Posts:
    203
    Is there a simple way to clear a render texture to a custom color before rendering to it?

    Something like this:

    Code (csharp):
    1.  
    2. void OnPreRender(){
    3.      someRenderTexture.color = Color.white; //But something that works :)
    4. }
    5. void OnRenderImage(){
    6.     for(int i=0;i<10;i++){
    7.          //Render some kind of accumulative (/frame) effect
    8.     }
    9. }
    10.  
    I'm working on an Image Effect that renders multiple passes each frame into a render texture and need to clear it each frame so I don't get a Motion blur effect. The rendertexture is created by a second camera and will then be combined with the rendered image from the main camera to complete the effect. Not sure that makes much sense...

    Help...

    /P
     
  2. Omar Rojo

    Omar Rojo

    Joined:
    Jan 4, 2007
    Posts:
    494
    create a quad and use a solid color shader that is the size of the camera frustrum, or use the camera clear function setting it to a solid color and set the color you want too.

    .ORG
     
  3. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    For now, you'll have to draw a fullscreen quad.

    We'll add something like GL.Clear in the future.
     
  4. Omar Rojo

    Omar Rojo

    Joined:
    Jan 4, 2007
    Posts:
    494
    In the 2.0 future ??? :D :D :D :D

    .ORG
     
  5. metervara

    metervara

    Joined:
    Jun 15, 2006
    Posts:
    203
    Thanks guys

    Ended up with this - there's two passes in my shader and I use the first one for clearing. Then i draw the second pass multiple times for the effect. Works great :)

    /P
     
  6. Omar Rojo

    Omar Rojo

    Joined:
    Jan 4, 2007
    Posts:
    494
    Let us see your miracle !

    .ORG
     
  7. metervara

    metervara

    Joined:
    Jun 15, 2006
    Posts:
    203
    It's for a project that will be public by mid august - and then it will all be revealed! :)

    /P