Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Bishmanrock · Feb 28, 2021 at 10:20 AM · rendertexturerender texture

Render Textures always appear on top?

Maybe this is how they're meant to work, but the Unity docs don't explicitly state so, so I'm wondering maybe I'm missing something.

I've been using a Camera Pixelate script I found online for a while on my Weapon Camera for my FPS game. It's been working great, but now that I've started to add UI elements I've noticed that camera renders the weapon over everything - including the HUD elements. I've played with the depth and sort order to no avail, so I'm wondering if it's just a genuine limitation, and if so what a better route would be.

The script originally used GUI.DrawTexture, however Googling suggested to use Graphics.DrawTexture instead. This has not made a difference.

CameraPixelate script:

 public class WeaponCameraTest : MonoBehaviour
 {
     public RenderTexture renderTexture;
 
     void Start()
     {
         int realRatio = Mathf.RoundToInt(Screen.width / Screen.height);
         renderTexture.width = NearestSuperiorPowerOf2(Mathf.RoundToInt(renderTexture.width * realRatio));
         Debug.Log("(Pixelation)(Start)renderTexture.width: " + renderTexture.width);
     }
 
     void OnGUI()
     {
         GUI.depth = 0;
         Graphics.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), renderTexture);
     }
 
     int NearestSuperiorPowerOf2(int n)
     {
         return (int)Mathf.Pow(2, Mathf.Ceil(Mathf.Log(n) / Mathf.Log(2)));
     }
 }



I thought the GUI.depth might've been the problem, but I've changed that to no avail. I also tried setting renderTexture.depth through code which doesn't appear to work.

And this is the Render Texture itself, although I've played with all the settings and observed no difference:

alt text

Maybe it's just my misunderstanding of how Render Textures work - if so is there a better solution I should be looking at? The purpose of this script is just to pixelate the weapon camera (e.g. the weapon being held in an FPS), but not the main camera.

ren.png (18.8 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Namey5 · Feb 28, 2021 at 09:22 PM

This doesn't really have anything to do with the RT - you are applying it via the IMGUI system, which will always be rendered on top of the scene (including UGUI). If you want it to draw before UI then the easiest way is to add it as a RawTexture underneath the rest of your HUD via the UGUI system.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bishmanrock · Mar 01, 2021 at 02:34 PM 0
Share

This seems to be the right route - thank you!

For anyone stumbling across this in their Googling: I had to create a Canvas under the player object, put a Raw Image on it, and then use the same CameraPixelate RT that the camera was utilising as its target texture. I still had further issues of clipping, these seem to be related to the fact that I was using several canvases and the sort order of the Raw Image only seems to apply to the canvas it sits in (i.e. it was still displaying over other canvases regardless of depth setting). There may be a proper way around this, but in my case I was able to just consolidate all the canvases to resolve the issue.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

113 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Prevent Render Texture clearing 1 Answer

Render texture for map doesn't render all objects. When given a Cinemachine 2d camera controller it renders the missing objects at the perspective of the main camera 0 Answers

Render particle system to texture. 0 Answers

Where can i find the RenderTexture component ? 1 Answer

Unity RenderTexture displays transparency when the front-most sprite contains alpha 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges