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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Graphics.Blit flips texture

Discussion in 'General Graphics' started by ThomasCreate, May 26, 2015.

  1. ThomasCreate

    ThomasCreate

    Joined:
    Feb 23, 2015
    Posts:
    81
    Hey there,

    For a project I need to render a game on a very wide but short resolution (5124 x 360), but output that to a regular full HD screen. The game is played on two "ribbons", each taking half of the vertical space (so 5124 x 180). I wrote a screen space shader that wraps those two ribbons so they fit inside the full HD resolution - so far, so good.

    However, I also need to use that wrapped output as a texture on a model for testing purposes. I figured I could just blit the output of the camera that shows the wrapped image on screen to the model, but for some reason the texture is vertically flipped after blitting it to another texture.

    Code (CSharp):
    1. void OnRenderImage(RenderTexture src, RenderTexture dest)
    2. {
    3.     //Blit the wrapped texture onto the camera output.
    4.     Graphics.Blit(_graphicsTexture, dest, _wrapMaterial);
    5.     //Blit the camera output onto a texture so it can be applied to a model. The texture in "dest" appears flipped in "_outputTexture".
    6.     Graphics.Blit(dest, _outputTexture);
    7. }
    8.  
    There isn't any anti aliasing post processing effect applied to any of the camera's, so that's definitely not it. Any ideas as to what I'm doing wrong?

    Thanks,

    Thomas

    EDIT:

    So I had an epiphany on the john (you know, as you do), and I figured that I'd try not reading the output of OnRenderImage directly (the dest render texture), but going over a temporary middle man instead. That solved the issue - hopefully this might help someone else in the future.

    Code (CSharp):
    1.  
    2. void OnRenderImage(RenderTexture src, RenderTexture dest)
    3. {
    4.     RenderTexture temp = RenderTexture.GetTemporary(1920,1080);
    5.     //Wrap the texture.
    6.     Graphics.Blit(_graphicsTexture, temp, _wrapMaterial);
    7.     //Blit the wrapped texture onto the camera output.
    8.     Graphics.Blit(temp, dest);
    9.     //Blit the camera output onto the texture for use on a model.
    10.     Graphics.Blit(temp, _outputTexture);
    11.     RenderTexture.ReleaseTemporary(temp);
    12. }
     

    Attached Files:

    Last edited: May 26, 2015
    Xaron and theANMATOR2b like this.
  2. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
  3. ThomasCreate

    ThomasCreate

    Joined:
    Feb 23, 2015
    Posts:
    81
    I am aware of this. However, my shader did not flip the texture on the render texture to which it was applied, so this doesn't apply here. The texture was flipped after copying it from the destination render texture to another one.
     
  4. andismithers

    andismithers

    Joined:
    Apr 12, 2019
    Posts:
    1
    I know this is an old question. however its the google hit for invert image.
    To inverted the image just use
    Code (CSharp):
    1. Graphics.Blit(src, dest, new Vector2(1.0f, -1.0f), new Vector2(0.0f, 1.0f)
    This inverts the Y and offsets from the top. Simple single blit operation.
    -andi