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 Nadafy · Oct 22, 2014 at 10:31 AM · shadertransparentinvisibleculling mask

How to make invisible others inside a invisible mesh!

I need to render some objects but 'mask' them off if they are in specific area! (inside a mesh or between two mesh)

I hope that made sense?

alt text

test.jpg (119.0 kB)
Comment
Add comment · Show 1
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 CodeElemental · Oct 22, 2014 at 11:55 AM 0
Share

If you have only relatively slow-moving objects you can maybe create a collidable area of your preference and when the desired object collides with it (i.e. enters the area) you make it invisible (disablew renderers/ or change into transparent shader or w/e), and reverse it when it stops colliding.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Oct 22, 2014 at 12:08 PM

Well, this can't be done with a mesh as masking geometry, but with mathematical planes. Here's a simply shader i've just written that takes 6 planes as parameters which define a volume that should be masked. Your cylinder has to use that shader and you need a script to setup the 6 planes. I've written a small script that uses 6 empty gameobjects to define those 6 planes. Each gameobject represents a plane in it's x-y-plane while the forward (blue axis) is considered "outside". So the volume that is "inside" of all those 6 planes will be clipped.

 Shader "Custom/ClipMeshShader" {
     Properties {
         _MainTex ("Base (RGB)", 2D) = "white" {}
       _Plane0 ("Top", Vector) = (0,0,0,0)
       _Plane1 ("Bottom", Vector) = (0,0,0,0)
       _Plane2 ("Left", Vector) = (0,0,0,0)
       _Plane3 ("Right", Vector) = (0,0,0,0)
       _Plane4 ("Front", Vector) = (0,0,0,0)
       _Plane5 ("Back", Vector) = (0,0,0,0)
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         LOD 200
         
         CGPROGRAM
         #pragma surface surf Lambert
 
         sampler2D _MainTex;
       float4 _Plane0;
       float4 _Plane1;
       float4 _Plane2;
       float4 _Plane3;
       float4 _Plane4;
       float4 _Plane5;
 
         struct Input {
             float2 uv_MainTex;
          float3 worldPos;
         };
 
         void surf (Input IN, inout SurfaceOutput o) {
             half4 c = tex2D (_MainTex, IN.uv_MainTex);
             o.Albedo = c.rgb;
             o.Alpha = c.a;
          float p0 = dot(_Plane0.xyz, IN.worldPos) + _Plane0.w;
          float p1 = dot(_Plane1.xyz, IN.worldPos) + _Plane1.w;
          float p2 = dot(_Plane2.xyz, IN.worldPos) + _Plane2.w;
          float p3 = dot(_Plane3.xyz, IN.worldPos) + _Plane3.w;
          float p4 = dot(_Plane4.xyz, IN.worldPos) + _Plane4.w;
          float p5 = dot(_Plane5.xyz, IN.worldPos) + _Plane5.w;
          if(p0<0 && p1<0 && p2<0 && p3<0 && p4<0 && p5<0)
              clip(-1);
         }
         ENDCG
     } 
     FallBack "Diffuse"
 }

Here's the script to set the shaders properties of our Material:

 //C#
 public class SetClipPlanes : MonoBehaviour
 {
     public Transform[] Planes; // out 6 empty gameobjects
     public Material mat;       // the material of the cylinder
     void Update ()
     {
         for (int i = 0; i < 6; i++)
         {
             Vector4 V = Planes[i].forward;
             V.w = -Vector3.Dot(V,Planes[i].position);
             mat.SetVector("_Plane"+i, V);
         }
     }
 }

edit
Keep in mind that "cutting" / clipping a mesh won't close the mesh at the cut like you have it in your example. It just masks the part in the middle. A shader can't render something that isn't there. If you need this you have to manually manipulate the mesh and literally cut out those parts and create new faces at the cut. This would equal what CSG does with boolean operations. However updating such geometry can be quite heavy but there are solutions out there for Unity

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to use the Terrain Transparency? 1 Answer

Shader that makes every other pixel not render? 1 Answer

Objects Not Visible In Low End Computer. (Shader Error) 1 Answer

How to adjust the transparency of the shader? 0 Answers

Transparent Shader Render Order Issue 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