- Home /
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
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:
import shader to project (shader code below)
create a primitive mesh
scale mesh so it covers whole screen but not larger then screen (exactly screen size)
make for mesh a material with this shader
make a fadeout texture (Alpha channel only used) and assign to material
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 } } }
PS disable whole renderer if you don't fade out screen due to perfomance reason
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
thanks, It did not work as (I)intended it loses the masking ability. Have to re-try/ test further
download package from link below and try do manually mask - if it works than it is 80% completed, just need to implement.
Your answer

Follow this Question
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