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
1
Question by dougmuir · Feb 26, 2016 at 09:49 PM · renderingvr

OnRenderObject is called more often than I expect.

I was doing some investigation by adding logging to OnWillRenderObject and OnRenderObject to understand when each is called. What I'm seeing is surprising me. I'm testing on GearVR, so I expected OnWillRenderObject and OnRenderObject to be called at most twice per frame, and potentially once if Unity is trying to eliminate duplicate work for each eye. Instead I'm seeing OnWillRenderObject called once per frame, but OnRenderObject called 6 times per frame. Strangely, two of the calls to OnRenderObject are occurring before OnWillRenderObject is called. I'd like to use OnRenderObject to draw some custom geometry, but not if it's going to cause the custom geometry to be drawn multiple times per frame. Can someone explain what's going on?

Comment
Add comment · Show 2
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 dougmuir · Feb 25, 2016 at 07:33 PM 0
Share

I added some additional logging about the state of Camera.current on each call to OnRenderObject, and what I'm seeing is that OnRenderObject is being called once per eye on 3 separate cameras. First, it's called twice (once per eye) with Camera.current == PreRender, then OnWillRenderObject is called, then it's called once per eye with Camera.current == my camera, then finally twice more (once per eye) with Camera.current == PostRender. I guess my question becomes, what are the PreRender and PostRender cameras, and should I be concerned about the performance implications?

avatar image callen · Feb 26, 2016 at 10:02 PM 0
Share

Since this is Unity-internal stuff related to a relatively new platform, I don't know how much luck you'll have here. But the info you've already managed to find out is pretty great so I wanted to say thanks!

I'm sure you know you could do this, but you could see what happens if you do your custom rendering only when Camera.current == my camera. I'd be interested to know if it works or if something about the Pre/Post rendering cameras is necessary for the graphic to display correctly in the H$$anonymous$$D.

In terms of getting it down to one render call, I don't know how that will work, because each 3D object needs to be rendered by both left and right camera for proper stereoscopy, and if I'm understanding it correctly you can't render with two cameras in one pass.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Fydar · Feb 26, 2016 at 10:06 PM

I would simply create the bool:

 public bool HasRunThisFrame = false;

and inside "OnWillRenderObject" or "OnRenderObject" (What ever one you find more consistent) and do something like this:

 public void OnRenderObject () {
      if (!HasRunThisFrame) {
           //TODO: Draw Objects to Screen
           
           HasRunThisFrame = true;
      }
 }
 
 public void Update () {
      HasRunThisFrame = false;
 }

That way, "OnRenderObject" will only run once per frame so you aren't wasting CPU power on drawing stuff needlessly to the screen.

Good luck - Fydar

Comment
Add comment · 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
0

Answer by dougmuir · Mar 03, 2016 at 02:04 PM

Turns out the additional calls were because of the Cardboard SDK -- we support both Gear and Cardboard, and it turns out the Cardboard SDK creates a PreRender and PostRender camera even when the Cardboard SDK is disabled. It appears that the extra cameras don't actually do anything when the Cardboard SDK is disabled, but the presence of the cameras does cause extra calls to OnRenderObject.

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to show FPS in the screen using latest Google VR package 0 Answers

VR Single Pass Rendering + Graphics Jobs Toggled On Broken 1 Answer

Unity profiler + Gear VR oscillating rendering speed despite no change in image 0 Answers

Galaxy S7 performance issues after upgrading Unity 0 Answers

Blackscreen rendered in Vive HMD when using Render Pipelines 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