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
1
Question by JChilton · Jul 24, 2012 at 10:44 PM · shadercullinghidinghalf

Partial object culling/cutoff

Essentially, are there any tried and true techniques for partial culling of objects in Unity that are of the same mesh? Such as an object that is on one side of a plane is no longer rendered, yet it is on the frontside.

Maybe even a shader that 'skips' a certain z distance? Like viewing through a portal that skips to the other side. So i could have a cube or a sphere with this 'portal shader' and it would hide anything inside of it.

examples:

  • Pulling a sword from an invisible portal, the sword is only drawn as it gets pulled out of the air.

  • Cheshire cat smile. (not really a planar cutoff)

  • Loss of limb. (fancy planar cutoff?)

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

2 Replies

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

Answer by Julien-Lynge · Jul 24, 2012 at 11:04 PM

This is an opinion question, so I'm giving you an opinion answer of how I would do it. There are many, many other ways both on the shader side and the mesh side.

The idea: use a shader that reads mesh vertex color (http://docs.unity3d.com/Documentation/ScriptReference/Mesh-colors.html). There are different ways to do this depending on whether your shader is written with ShaderLab, vertex/fragment (Cg/HLSL), or as a surface shader. How to do this is a separate question, but here's a couple links to get you started:

  • ShaderLab binding of vertex color for use in the shader: http://docs.unity3d.com/Documentation/Components/SL-BindChannels.html

  • Cg shaders: http://answers.unity3d.com/questions/189584/how-to-get-vertex-color-in-a-cg-shader.html

Whenever you need to calculate which vertices of the mesh are visible and which are not (every frame while your sword is getting pulled), you loop through the vertices and assign the vertex color like this pseudocode:

 foreach (vertex in the mesh)
 {
   if (vertex is in the bounding space you want to be invisible)
     vertex color = white
   else
     vertex color = clear
 }

Now all you have to do in your shader is multiply the color by the vertex color. Multiplying by white won't change the color, while multiplying by clear will result in clear. You could even do fancy effects like energy fade-ins: if inside the bounding area, make clear, if just outside the bounding area, fade from clear to bright green (or whatever color), if further out fade from bright green to white.

For your last option (loss of limb), you'd have to do some procedural mesh generation that's worth a separate question and a bit of math. Rather than changing the vertex color of vertices in the bounding area, you'd remove them from the mesh entirely, cut their triangles with the plane of the bounding area, build a ring of the cut triangles, and create a mesh around the ring.

Comment
Add comment · Show 3 · 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 JChilton · Jul 25, 2012 at 01:44 AM 0
Share

That's awesome. Thanks for both solutions, gave me a clearer idea of what I'm looking for. I found an alternative solution that's an acceptable workaround in the meantime though (my objects are static, and only will be viewed from one hemisphere). I'll definitely look into this later on if I come across a similar predicament.

avatar image JChilton · Jul 25, 2012 at 01:47 AM 0
Share

What kind of effect would I see of multiplying a vertex by clear, if the adjacent vertex outside of the bounding area is fairly far away? Would it fade from one vertex to the next, or would that all depend entirely on how the shader itself renders it?

avatar image Julien-Lynge · Jul 25, 2012 at 04:24 AM 0
Share

Yeah, it would interpolate between the vertices. If you wanted it to be a sharp cutoff, other solutions (procedural mesh deformation or code at the vertex shader level) would probably be better.

avatar image
1

Answer by cowlinator · Feb 10, 2015 at 02:10 AM

You could use Clip(), as seen in "Slices via World Space Position" at http://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html

I've heard mixed opinions about the performance of Clip() ( http://forum.unity3d.com/threads/clip.257310/#post-1701475 )

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

Hiding parts of mesh but only on defined objects 0 Answers

Can the Cull option in shader improve perfomances ? 2 Answers

Cullingmask issue. 0 Answers

How is a polygon determined to be front facing or back facing? 1 Answer

How to fix weird culling problem? 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