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 manny003 · Dec 08, 2016 at 07:44 PM · shaderrenderingperformanceoverdraw

Trying to Reduce Overdraw: How can I clip select screen areas?

I have a 2D game with multiple cameras. Screenshots shows overdraw rendering.

  1. First, I have a background effect camera at the lowest depth (-12) to render some particles of various sizes floating about to give a visual interest around the edges of the screen as opposed to just a solid color or static image. Screenshots are for the tvOS widescreen version. Please see image part A.

  2. On top of that, I have other cameras which draws my actual game objects. But that actual play area of my game is smaller than the screen and is fixed - never moves or changes size. I also know that everything that I draw there will be opaque -- none of the background layer effects will be visible through it. (Blue box represents actual play area): Please see image part B.

  3. As you can see, about of a third of the screen has needless overdraw. I've tried to program the background effect particles to float away and avoid the center but I can only do that so much before things look "weird" to me. Ideally, I'd like to find a way to tell the background effect camera to avoid/ignore a section of the screen where I know I will be rendering other stuff on top -- a custom shaped clipping area. My first thought would be to place a quad with a special "clipping shader" that tells the renderer "ignore pixels in this area. A black empty rectangle in the center is what I'd like my background effect camera to be able to do but without additional overdraw. Please see image part C.

How can I do this? If this can be done via a shader as I hope, can someone help write?

Thanks, Manny

alt text

overdraw-combo.jpg (357.9 kB)
Comment
Add comment · Show 3
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 getyour411 · Dec 08, 2016 at 08:12 PM 0
Share

Have you looked at Occulsion culling?

avatar image manny003 getyour411 · Dec 08, 2016 at 08:24 PM 0
Share

I've turned on the camera "Occlusion Culling" but with no apparent effect. The overdraw rendering mode in my scene view still shows apparent overdraw -- or does that not properly reflect whats actually going on?

avatar image getyour411 manny003 · Dec 08, 2016 at 08:52 PM 1
Share

After re-reading your details and the comment below, I'm not sure occlusion culling will help in this case. If you do have a different "main camera" view it might benefit from occlusion culling though I'm not sure about the effect for a 2D camera. Turning it on probably isn't enough, like Lightmapping you have to do some setup - check the doc it explains it well.

https://docs.unity3d.com/$$anonymous$$anual/OcclusionCulling.html

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Pangamini · Dec 08, 2016 at 08:12 PM

Make sure the occluder is drawn first with write to the depth buffer; Make sure the underlying geometry fails the z-test under the occluder. This should help

Edit: By occluder, I don't mean any particular unity class (means it's unrelated to umbra occlusion culling), but simply any geometry that's rendered into depth buffer.

Comment
Add comment · Show 10 · 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 manny003 · Dec 08, 2016 at 08:27 PM 0
Share

I'm not sure I follow. Is the "occluder" a mesh object like my quad? Should it be rendered by the same camera as the one I'm using for my background effect? I thought occlusion culling was used primarily for 3d games -- does it work the same way for 2D games?

I've search for articles and tutorials to help me explain and use but nothing that talks to my specific need -- do you know of any?

$$anonymous$$anny

avatar image Pangamini manny003 · Dec 08, 2016 at 08:33 PM 0
Share

It's not occlusion culling. Pixels are discarded from shading if they fail the z-test. Just render any quad that writes the depth; make it write a very low depth (so other parts of the scene have higher depth / distance from the camera) and make sure it's drawn first (use shader/material render queue for that). Occlusion culling (Umbra) culls entire objects / meshes, so drawcalls are reduced too; this is not the case. However you could try to utilize umbra (or some custom solution) to discard objects completely if they are entirely hidden by your quad. But just discarding pixels with z-test should increase performance, at least of the pixel shading

avatar image manny003 Pangamini · Dec 09, 2016 at 10:57 AM 0
Share

Thanks for your input. However, try as I might, I having a hard time wrapping my head around this. Are you suggesting, like I think you are, that this is accomplished using a pixel shader? I can't seem to find examples of "rendering to depth buffer" as you suggested.

I have never written a shader and am having to start from scratch. Is there a known shader that I can use?

Show more comments
Show more comments
avatar image manny003 manny003 · Dec 09, 2016 at 03:45 PM 0
Share

That's what I did. The Tris and Vertices differences only reflected the quad mesh being turned on and off and the Set Pass reflect the extra draw call I noted above. What's gong on at the lower level of pixel fill rate -- I cannot tell.

avatar image Pangamini manny003 · Dec 14, 2016 at 12:57 PM 0
Share

There will be no difference in triangle/vertex count, nor the drawcall/batch count, because you are not culling drawcalls / geometry. The 'overdraw' mode scene view simply renders everything with a custom additive shader, it won't actually show you the exact overdraw; All you can do now is benchmark. Write a super expensive shader and render it a lot under the occluded area. Then go playmode, and check the fps/ms with the occluder on and off and see if there's a result. It also depends on the HW, but AFAI$$anonymous$$ modern cards will discard pixels from the pixel shader if they fail the depth test - you should see the result

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

90 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

Related Questions

Low Performance when drawing many objects 2 Answers

uGUI Image without transparency/ opaque render queue 0 Answers

Drawing objects based only on layer order with no overdraw 1 Answer

Is the template containing Shader Graph heavy on performance? 0 Answers

Is a shader with selective passes faster than a single-pass which uses lerp to enable/disable shader effects? 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