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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by rjr · Jul 28, 2016 at 01:25 PM · shadersmaskdepthmaskalphablend

Shader For cut hole and alpha blend

Shaders: Hey guys, just learning shader concept, i am looking for a shader to achieve following Effect:

Say that there is a wall having some texture, if i place a quad in front of the wall, based on the alpha value of the quad texture the wall should be masked,

1)Where there is quad texture alpha = 0 quad has to get the wall's texture in it
2) Where there is quad texture alpha = 1 quad has to mask the wall completely
(Or vise versa )
3) If the alpha value of the quad in-between 0 to 1 based on that it has to blend(transparent) with the wall.

Similar kind of depth mask effect, but it uses mesh shape to cut the object and results in sharp edges , but in my case i want to use alpha value of the texture to mask the wall.
Hope it makes some sense

Comment
Add comment · Show 4
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 Namey5 · Jul 29, 2016 at 06:11 AM 1
Share

Could you provide maybe a pictorial example. It's hard to get a grasp on what you are trying to achieve. You could have an alpha blended shader and simply discard certain pixels as you would in a cutout shader, but I don't know if this is what you mean.

avatar image rjr Namey5 · Jul 29, 2016 at 06:59 AM 1
Share

alt text

Hey Namey5 thanks for your time. This is the effect i want to achieve, Red,Green,Blue box is a quad, based on alpha value of the quad the wall pixels are drawn, and if two quads overlaps then (like red and blue) is it possible to get the highest alpha value of that point and render the pixel ? The quad texture is like this, black is transparent, white is opaque (if needed i can have visa versa texture alpha value) alt text

01-2.jpg (355.6 kB)
02.png (28.5 kB)
avatar image Namey5 rjr · Jul 29, 2016 at 01:09 PM 1
Share

I believe the stencil buffer may hold what you are looking for.

https://docs.unity3d.com/$$anonymous$$anual/SL-Stencil.html

Having not used it myself, however, I cannot say for sure. I'll try and run some tests tomorrow.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MakinStuffLookGood · Nov 15, 2016 at 05:33 PM

There are many many ways to achieve this depending on the needs of your project. Here are a few ideas to get you started:

  • If you only need circles, set uniform vectors on the wall's material that define where in world space the circles are, in your fragment shader, use a fixed radius, and feather the edges exponentially.

  • If you don't need an arbitrarily high number of cutouts, define the cutout shapes as extra textures, and use a Vector4 to pack in the texture space x/y and width/height of the shape.

  • For a truly catch all solution, you could render another camera to a rendertexture that captures the cutout shapes and makes that RT available in shader (via Shader.SetTexture). The wall (and anything else that needs the cutout) can get their position in screen space during the vertex shader, and use use their screen space coordinate remapped to the range 0..1 to sample an alpha value from the Cutout rendertexture!

Those examples are roughly sorted in increasing complexity, and also increasing gpu demand. I'd recommend you roll with the minimum solution that will work for your project (though the catch all solution would be a fun experiment/learning exercise)!

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

Shader help - 2d black and white polygons where black shows one background image and white shows another -1 Answers

A question about clipping area 0 Answers

Mask intersection between Line Renderer and Sprite (Shaders) 0 Answers

Depth mask with alpha / adding alpha to frag grabpass shader 0 Answers

2D stencil cut out 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