Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Rendertexture feedback effect

Discussion in 'Shaders' started by tmcthee, Aug 2, 2019.

  1. tmcthee

    tmcthee

    Joined:
    Mar 8, 2013
    Posts:
    119
    Hi,

    tldr: Is there any project setting (or anything else) that would stop a render texture rendering to itself?

    I have "video feedback" type effect that seems pretty easy to do.
    • Create a "render texture" with a camera "renderTextureCamera".
    • Create a quad and apply "render texture" to it.
    • Point renderTextureCamera at the quad and the "render texture" feeds back on itself in a quite an appealing way.
    feedback.png feedback2.png

    So far so good.
    Problem is, I tried to create the same effect in an old project that we're currently updating and I cant get it to work. When the "renderTextureCamera" looks at the render texture. The render texture appears black to it.
    The render texture itself is fine, but the render texture within the render texture is black, so you don't get any feedback and it just looks like this.

    feedbackFail.png

    I'm wondering if there's some setting hidden somewhere in the old project that's breaking it.
    I can get it working very easily in any new project but in our old project it just doesn't work.
    I thought perhaps it might need a particular rendering path or something like that, but the cameras are all set to "forward". So maybe there's some other setting that's been set differently during the old project's development.
    All projects are using the same version of unity.

    Thanks in advance
     
  2. DaveL99

    DaveL99

    Joined:
    Jul 5, 2018
    Posts:
    22
    Just to check the obvious (as sometimes the most obvious things are the easiest to miss!) ... Have you checked the "Clear Flags" on your renderTextureCamera? I'm assuming it should be "Don't Clear", but maybe in your old project it's been set to "Solid Color"?

    However, does what you are doing actually result in the same texture being simultaneously bound as both a destination render-target and a source texture during the camera's rendering? If so, on some graphics APIs like OpenGL that is "undefined behaviour", and on others I think may be flat-out prohibited. Are your new & old projects both using the same graphics API?

    Have you looked to see if the Frame Debugger reveals anything?
     
  3. tmcthee

    tmcthee

    Joined:
    Mar 8, 2013
    Posts:
    119
    Thanks Dave,
    Clear flags don't make any difference in the working version. As long as the camera can "see" the render texture its drawing to the effect works.
    I think you might be onto something regarding the apis. Those are different in the old project. I can't check now because we're making some major changes to the project in that area. But when I can I'll try switching them about. I expect you're right about that being the cause.
     
    DaveL99 likes this.
  4. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    Curious to hear how this ended up, as I'm expecting to get feedback from my shader but it's just black (render texture looks ok by itself, but shader only seems to receive black)..