x


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

more ▼

asked Jun 14 '12 at 11:57 AM

Uttpd gravatar image

Uttpd
0 1 2 3

is it actual?

Jul 19 '12 at 06:30 PM ScroodgeM

realtime? yes

Jul 19 '12 at 07:17 PM Uttpd
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

http://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
		}
	}
}
more ▼

answered Jul 19 '12 at 08:51 PM

ScroodgeM gravatar image

ScroodgeM
7.6k 2 6

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

Jul 19 '12 at 08:56 PM ScroodgeM

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

Jul 20 '12 at 09:32 AM ScroodgeM

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

Jul 20 '12 at 11:30 PM Uttpd

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

Jul 21 '12 at 03:52 AM ScroodgeM
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1655
x94
x12

asked: Jun 14 '12 at 11:57 AM

Seen: 1248 times

Last Updated: Jul 21 '12 at 03:52 AM