Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Prefab · Jun 04, 2016 at 10:39 AM · shadermeshrenderskinned

Can a shader be used to not render parts of a skinned mesh?

I have several high poly, skinned meshes that move around the scene while animating. Often, one mesh intersects another and they move together at the same speed in the same direction. For performance reasons I would like the surface of the mesh that is inside (and therefore not visible to the camera) to not be rendered. Because the meshes move around the scene uncontrolled, the meshes can intersect in any number of ways. Also since it is a single mesh I cannot deactivate it or turn off its renderer, since a part of the object may still be visible.

Is it possible for a shader to know (based on depth perhaps) which parts of its surface have been occluded by another object and as a result stop rendering those parts of its surface?

alt text

screenshot-04-06-2016.png (299.1 kB)
Comment
Add comment · Show 8
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 tanoshimi · Jun 04, 2016 at 11:17 AM 1
Share

Assu$$anonymous$$g your shaders write to/test the depth buffer (i.e. ZWrite On and ZTest LEqual, which are default for any non-transparent shaders) then the behaviour you describe already happens automatically - when a candidate pixel is about to be rendered, if there is already a pixel in the depth buffer that is closer to the camera then the candidate will be culled. Unless I've misunderstood your question, in which case perhaps a screenshot would help of what you're trying to describe..

avatar image Prefab · Jun 04, 2016 at 01:08 PM 0
Share

Ok I've added a screenshot. What I need is for the part of the small sphere that is inside the large sphere to not be rendered. This is similar to a boolean operation except the mesh itself would not be changed, just the intersecting polygons would not be rendered. Is this more clear?

avatar image Eudaimonium · Jun 04, 2016 at 01:14 PM 1
Share

To the best of my knowledge, no. You cannot use a shader for the purpose you described. A shader is a program that ultimately calculates the color of a pixel of an object it is assigned to. It works on the object's level (and various parts of the shader program work on vertex level and pixel level) and cannot have any knowledge of any nearby objects of their surface properties.

Like tanoshimi said, the depth check happens automatically anyway, but if the background object gets rendered first, and then foreground object draws over it, then yeah you're dealing with "overdraw", essentially you're wasting time by drawing the background object.

$$anonymous$$ost 3D Engines, Unity included, do their best to overcome this problem by drawing closest objects first. But long story short, no there really isn't anything you can do about it in your particular example.

In fact you'd probably spend more CPU or GPU time figuring out what's occluded/clipped and discarding those surfaces, then simply rendering everything without such conditions.

If your currently struggling with performance, you're looking at the wrong solutions. Reduce the number of objects on scene, or use simpler shaders to draw them, use static occluders and Occlusion bake as much as possible. If you're using multiple dynamic lights, use deferred renderer. If not, use forward renderer and bake all non-dynamic lights in. If you have any custom written shaders, give them a once-over against known shader optimization guides to make sure they're not running slower than they should.

avatar image Prefab · Jun 04, 2016 at 01:30 PM 0
Share

@Eudaimonium , ok how about if ins$$anonymous$$d of trying to figure out exactly what is intersecting what, I only use a texture. So for example all of the black parts of the texture would not get rendered but the white parts would get rendered. This is similar to an alpha texture, but it would not make the surface only transparent, it would not render those polygons.

avatar image Eudaimonium Prefab · Jun 04, 2016 at 01:35 PM 0
Share

And how do you intent to figure out which texture parts are white and which are black?

From where does this texture come from? How will you render out this texture? One for each character? How many render targets will that come down to?

How would you "not render" what's on the black texture?

I think you're completely going about it the wrong way. There is no reliable way to skip rendering of clipped parts of animated mesh, at least not in the performance preserving reasons. Focus your optimizations on important stuff. I named a few up there.

avatar image Prefab Eudaimonium · Jun 04, 2016 at 01:49 PM 0
Share

I can use a set of premade textures, and then switch between them at runtime under certain conditions, that part I can work out. What I'm not sure of is how the shader would interpret the texture and render only the white parts of the surface, culling the black.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

61 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

Related Questions

Shader does not display properly in game/editor view, but building it works. 0 Answers

Can a shader render darkness inside a mesh? 2 Answers

Textures not showing up 0 Answers

How do I render content already in graphics ram? 0 Answers

Shader to make a quad work like a canvas 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