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
  4. Dismiss Notice

Question Reflection in Render Texture that doesn't exist in the Camera getting the Render Texture

Discussion in 'General Graphics' started by Curturp, Sep 1, 2022.

  1. Curturp

    Curturp

    Joined:
    Feb 21, 2021
    Posts:
    2
    I have a screenshot system in place that will use a camera to generate a render texture which converts to a PNG, and I'm getting a strange reflection issue in some of my shots.
    Here's a quick screenshot I grabbed with the snipping tool of my Game View Game View.png
    Here's a screenshot I got using the Screenshot system Screenshot.png

    I've used this screenshot system to take screenshots in multiple projects and this is the only time it's come up. Its also only shows the weird reflections when taking screenshots inside the building. If I take exterior shots, there's no reflections.

    And here's the code for my screenshot system:
    Code (CSharp):
    1. public void Save(RenderTexture rt)
    2.     {
    3.         Texture2D tex = new Texture2D(rt.width, rt.height);
    4.  
    5.         RenderTexture.active = rt;
    6.         tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
    7.         RenderTexture.active = null;
    8.  
    9.         byte[] bytes = tex.EncodeToPNG();
    10.  
    11.         string path = Application.dataPath + "/360ImageCapture/Pictures/" + photoName;
    12.  
    13.         if (File.Exists(path + fileType))
    14.         {
    15.             duplicateNumber += 1;
    16.             path = path + duplicateNumber + fileType;
    17.         }
    18.         else
    19.         {
    20.             duplicateNumber = 0;
    21.             path = path + fileType;
    22.         }
    23.  
    24.         File.WriteAllBytes(path, bytes);
    25.         Debug.Log("Saved Image to " + path);
    26.     }
     
  2. nomadshiba

    nomadshiba

    Joined:
    Jun 22, 2015
    Posts:
    27
    Idk but it looks like Screen Space Ambient Occlusion texture has been scaled up and doesnt line up with the base image

    you can notice shadows in the first image at the corners of the walls and that TV unit doesnt exists in the second image, i mean it exist but scaled up and doesnt line up

    idk why would that happen or how, im just saying that it just looks like that
    where do you get the RenderTexture from?
     
    Curturp likes this.
  3. Curturp

    Curturp

    Joined:
    Feb 21, 2021
    Posts:
    2
    This was it! Thanks for pointing it out. Still not sure why it's misaligned the way it is, but it's good to know the source of the problem.

    The RenderTexture is one I made in the Asset Folder and assign to the system in the Inspector.
     
  4. georgerh

    georgerh

    Joined:
    Feb 28, 2020
    Posts:
    72
    This is a long shot, but I've seen the postprocessing package apply changes one frame late. Maybe it works if you assign the render texture, wait for the next frame in a coroutine and then save out the texture.