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 Galfaroth · Jan 20, 2015 at 07:25 PM · shaderalphamaskdepthcutout

Cut out shader with geometry depth and alpha

Hello, I'm trying to do a shader like shown on image: alt text The shader I've found on the forums cuts out everything on camera till background. But I would like it to cut only the depth of the box that have the material applied. So I want to see a geometry beneath. But also be able to apply the masking texture. Could you please help me with the shader that would do what I would like? I'm totally noob in shader language but I guess it's an easy thing for somebody who knows them well :).

alt text

Here is the shader:

  Shader "Alpha Test Depth Mask" {
       
      Properties {
          _MainTex ("Texture", 2D) = ""
      }
       
      Category {
          Tags {Queue = Background}
          ColorMask 0
       
          SubShader {Pass {
              GLSLPROGRAM
              varying lowp vec2 uv;
       
              #ifdef VERTEX
              void main() {
                  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
                  uv = gl_MultiTexCoord0.xy;
              }
              #endif
       
              #ifdef FRAGMENT
              uniform lowp sampler2D _MainTex;
              void main() {
                  if (texture2D(_MainTex, uv).a > 0.99) 
                      discard;
              }
              #endif      
              ENDGLSL 
          }}
      }
       
      }
problem.jpg (60.8 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 Chris333 · Jan 20, 2015 at 07:34 PM 0
Share

Hi, idk if you already found this but maybe this is what you want or at least it helps someway. http://unitycoder.com/blog/2012/02/22/x-ray-cutout-shader-with-mouse/

avatar image Galfaroth · Jan 20, 2015 at 07:46 PM 0
Share

Hi, that could be it, but you can't define your own alpha mask. Here you use the X,Y,Z,W coordinates. What I need ins$$anonymous$$d is 'apply material to the geometry and make it work'. But that might be a good starting point for other answers!

avatar image developer_arni Galfaroth · Sep 12, 2015 at 11:12 AM 0
Share

Hi Galfaroth, found any solution yet? I am currently stuck with the same issue, and would love some guidance :)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

An Outline like the Editor does in game, with transparency 1 Answer

Shader: Cutout behavior mixed with masking behavior 0 Answers

Making a cutout semi-transparent? 1 Answer

Changing AlphaSelfIllum Shader to use Cutout? 2 Answers

How do you setup Depth Bias Alpha for Shaders? 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