Search Unity

Question Can I draw render texture without graphics.blit

Discussion in 'Shaders' started by glucosetong, Jan 21, 2021.

  1. glucosetong

    glucosetong

    Joined:
    Aug 10, 2017
    Posts:
    17
    Hello there. I am trying to doing some sort of field-calculation base on a render texture.

    I need to do this every frame:
    Code (CSharp):
    1. while ()
    2.         {          
    3.             Graphics.Blit(tex0, tex1, _material);          
    4.         }
    Document mention Graphics.Blit draws a full-screen quad. If I loop for 30 times, this will cause performance problem. Is there a more efficient way to do this?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    Don't do it 30 times?

    You'll need to be more specific about what you're trying to accomplish. Not necessarily in terms of what you're currently doing, but what the end goal is.
     
    glucosetong likes this.
  3. glucosetong

    glucosetong

    Joined:
    Aug 10, 2017
    Posts:
    17
    Last edited: Jan 21, 2021
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    There's no reason to run that 30 times. 12 times is kind of the upper bounds of the max number of times you'd need to run it, as that would entirely flood fill a 4096 x 4096 texture from a single pixel in a corner. 30 iterations would flood fill a 1,073,741,824 x 1,073,741,824 texture!

    Depending on your needs, you may want to do your flood fill at a lower resolution, or at least calculate the max number of iterations you need for the resolution you're rendering at.
     
  5. glucosetong

    glucosetong

    Joined:
    Aug 10, 2017
    Posts:
    17
    Thanks for the reply. SDF is only the first part of what I am trying to do. I am trying to do accumulated SDF, so it is actually vector-distance field. I need to run SDF twice then superposition then SDF again. :)