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
0
Question by Uttpd · Jun 14, 2012 at 11:57 AM · shaderblendingdepthmask

Depth Mask with Blending Edge

I´m trying to get blended/ fading edges from a Mask. Using the depth mask shader (source wiki). with this modified version I can get the alpha/ blending information on the mask to control the diameter off the mask (base Alpha Cutoff)

[CODE]Shader "Transparent/Mask" {

     // by moffatjason.

 Properties 

 {
     _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
     _Cutoff ("Base Alpha cutoff", Range (0,.9)) = .5
 }

 SubShader {

     // Render the mask after regular geometry, but before masked geometry and
     // transparent things. 
     
     Tags {"Queue" = "Geometry+10"}
     
     // Don't draw in the RGBA channels; just the depth buffer

     ColorMask 0
     ZWrite On
     
     Pass 
     
     {
         AlphaTest LEqual [_Cutoff]       
         SetTexture [_MainTex] {
             combine texture * primary, texture
         }

     }

 }

}[/CODE]

...But Im trying to get Blending/ Fading edges instead of the solid cut i´m getting.

PS: made same thread in unity forum with images

Comment
Add comment · Show 2
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 ScroodgeM · Jul 19, 2012 at 06:30 PM 0
Share

is it actual?

avatar image Uttpd · Jul 19, 2012 at 07:17 PM 0
Share

realtime? yes

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ScroodgeM · Jul 19, 2012 at 08:51 PM

zammyart.com/mask.unitypackage

move slider at transparent cube's material and check is it what you are looking for

you can also repeat this yourself:

  1. import shader to project (shader code below)

  2. create a primitive mesh

  3. scale mesh so it covers whole screen but not larger then screen (exactly screen size)

  4. make for mesh a material with this shader

  5. make a fadeout texture (Alpha channel only used) and assign to material

  6. got it. slide a single slider in material and you got greyscale effect by mask from texture

    Shader "Transparent/Mask" { Properties { _MainTex ("Alpha (A) only", 2D) = "white" {} _GreyPower ("Grey color power", Range(0,2)) = 1 } SubShader { Tags {"Queue" = "Geometry+10"} GrabPass { } Pass { Fog { Mode Off } Blend SrcAlpha OneMinusSrcAlpha

              CGPROGRAM
     
                 #pragma vertex vert
                 #pragma fragment frag
         
                 sampler2D _GrabTexture;
                 sampler2D _MainTex;
                 float _GreyPower;
     
                 struct appdata
                 {
                     float4 vertex : POSITION;
                     float4 texcoord : TEXCOORD0;
                 };
     
                 struct v2f
                 {
                     float4 pos : SV_POSITION;
                     float4 uv : TEXCOORD0;
                 };
     
                 v2f vert (appdata v)
                 {
                     v2f o;
                     o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                     o.uv = float4(v.texcoord.xy, 0, 0);
                     return o;
                 }
     
                 half4 frag( v2f i ) : COLOR
                 {
                     half4 c = tex2D(_GrabTexture, float2(i.uv.x, 1 - i.uv.y));
                     c.rgb = (c.r + c.g + c.b) * 0.33;
                     c.a = saturate(tex2D(_MainTex, i.uv.xy).a + _GreyPower - 1);
                     return c;
                 }
                 ENDCG
             }
         }
     }
    
    
    
    
    
Comment
Add comment · Show 4 · 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 ScroodgeM · Jul 19, 2012 at 08:56 PM 0
Share

PS disable whole renderer if you don't fade out screen due to perfomance reason

avatar image ScroodgeM · Jul 20, 2012 at 09:32 AM 0
Share

PPS this shader can be simple modified to fade based on fade start time and fade speed - so you needn't to set grey color power each frame, just a start time and speed one time at srart fading

avatar image Uttpd · Jul 20, 2012 at 11:30 PM 0
Share

thanks, It did not work as (I)intended it loses the masking ability. Have to re-try/ test further

avatar image ScroodgeM · Jul 21, 2012 at 03:52 AM 0
Share

download package from link below and try do manually mask - if it works than it is 80% completed, just need to implement.

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

Blending normal texture and texture made with shader 0 Answers

"Blend SrcFactor DstFactor, SrcFactorA DstFactorA" Does not work 2 Answers

Shader: Add one image's alpha to the other while keeping it unlit 1 Answer

Is it possible to change blend mode in shader at runtime? 1 Answer

Intersection / Geometry blend shader graph problem 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