Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 maikkel · Aug 15, 2011 at 09:28 AM · guirendertexturecustom

Custom GUI System RenderTexture (Ortographic Cam) vs Perspective

Hello, I'm trying to implement my own GUI-System into Unity.

I don't want to use OnGUI because of the well known performance issues.

Altough I have a license for EZGUI, i'd like to create my own system so i can learn something new.

As I see it, there are 2 Approaches:

  1. Using a second orthographic camera for the GUI and overlaying it on the main camera using a Render Texture.

  2. Keep everything in the Perspective Camera and calculating the correct Distance/Scale of the Object for it to be pixel perfect.

Most people seem to go for the 1st approach. Isn't there quite a bit of Overhead in this, because of the render texture?

I prefer approach 2. I already made several tests and it works surprisingly well. I just calculate the correct Scale of the Object (plane) from the distance to camera (with some trigonometry). This way the texture is pixel perfect (after moving it 0.5 pixels, took me forever to figure this one out...). Even drag and drop works like a charm. For MouseOver- or Click-effects I just move the UV coordinates of the mesh (I don't use Material Offset, so the Objects can still be batched).

I know this approach is quite a bit more complicated (and also more difficult to maintain) but I think performance-wise it's better.

What are your thoughts?

Should I continue (I intend to code a full framework like EZGUI) like this or should I Switch to the Orthographic Approach with a RenderTexture and second camera. What are the Overheads of a Rendertexture?

Comment
Add comment · Show 4
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 Waz · Aug 15, 2011 at 10:55 AM 0
Share

I can't see those options out-perfor$$anonymous$$g OnGUI. I suggest you run some benchmarks before you get too far.

avatar image equalsequals · Aug 15, 2011 at 01:26 PM 0
Share

Why not just use a second orthographic camera rendering on top of your perspective camera clearing depth only?

avatar image maikkel · Aug 15, 2011 at 08:42 PM 0
Share

How would I just render the second camera on top of the main cam, without using a Rendertexture? Is that possible? I was looking for something like that but didn't find anything. Wouldn't it be some overhead just because there's a second camera to render?

I will do some benchmarks then. I think the main gain in performance should come from all of it being just 1 drawcall (using a texture atlas), that's the reason why EZGUI is faster than OnGUI. The calculations only happen at Awake(), after that everything is just static planes in front of the camera.

avatar image equalsequals · Aug 15, 2011 at 08:59 PM 0
Share

submitted answer with step-by-step instructions of how to set that up.

2 Replies

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

Answer by equalsequals · Aug 15, 2011 at 08:57 PM

Like I said in my comment, just use a second camera.

  1. Create a new camera, set it to be orthographic. (Also, remove any unneeded components such as GUILayer, FlareLayer, AudioListener)

  2. To maintain pixel-perfect set the orthographic size to be exactly one half of the screen height (ie if res is 1024x768, ortho size is 384)

  3. Create a new layer and call it "UI" or something - set the GUI Camera's culling to cull only this new layer.

  4. Now on the clear flags of the camera, set that to "depth only".

  5. Select the other camera, set it's culling layers to not cull "UI".

  6. Now any UI element should be set to the layer UI, and fall within the GUI Camera's frustum.

Note - You should also ensure that the depth of your UI camera is greater than your Main Camera, else you won't see anything.

Hope that helps.

==

Comment
Add comment · Show 4 · 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 maikkel · Aug 15, 2011 at 09:15 PM 0
Share

Oh wow, I didn't know that two cameras just automatically render over each other (with different depth settings). I tried this once and it didn't work, i probably forgot something... So I thought this would only be possible with a render texture.

Thanks for your Guide, I'll try it out. I probably wasted a LOT of time with all this trigonometry stuff...

avatar image maikkel · Aug 15, 2011 at 09:21 PM 0
Share

I found my mistake, forgot the "depth only"-flag when testing this. Now I feel stupid...

avatar image JasonM · Nov 03, 2011 at 06:26 PM 0
Share

I tried this and everything is good, except for one thing. When I set the ortho size to 360 (im working in 720) all my gui objects get suuuper tiny and I have to make them huge in order to see them. I set the size to 1 and its more reasonable, I guess for me it doesnt even matter if I have pixel-perfect. But hopefully you can clarify. Thanks for the great walkthrough!

avatar image Waz · Nov 03, 2011 at 11:31 PM 0
Share

OrthographicSize is in meters (or whatever your world units are), not in pixels (which is what I assume you mean by "working in 720").

avatar image
0

Answer by JeroenAnimator · Nov 13, 2012 at 05:55 PM

Ok that works great but I have a question. I use a custom gui setup with an overlay orthographic camera the way you explained.

However I use OnmouseOver events for my buttons that are gameobjects with collider's. This works fine with a perspective camera but orthographic doesn't seem to trigger the onmouseover event.

However I need to use an orthographic camera to keep the gui buttons in position with different aspect ratio's. Any ideas?

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 AlucardJay · Nov 13, 2012 at 05:55 PM 0
Share

Hi There.

Please don't post comments as answers. Post comments by clicking the [add new comment] button, a window then open for you to type in. Answer fields are for answers only, as this is a knowledge base.

You can convert this answer to a comment (or just edit your original question), you'll also get a better chance of getting an actual answer if the main list shows none or one answer in blue =]

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

7 People are following this question.

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

Related Questions

Using different custom inspectorscripts 1 Answer

is it possible to use completely custom made gui elements for unity's extension? 0 Answers

Hierarchy pane like context menu 1 Answer

RenderTexture causes memory problems 2 Answers

Custom GUI Button is Black 1 Answer


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