- Home /
Blur the alpha part of a shader
First I explain what I want to achieve. My goal is to get a soft shadow alternative running on iOS (because unity soft shadows does not work on this plateform). I made a "transparentShadow" shader that is fully transparent but receive the shadow. Here is what I get with my shader and hard shadow :
Here is my code :
Shader "Custom/Transparent-Shadows-blur"
{
Properties
{
// Shadow Stuff
_ShadowIntensity ("Shadow Intensity", Range (0, 1)) = 0.6
_ShadowBlur ("Shadow Blur", Range (0, 0.01)) = 0.006
}
SubShader
{
Tags {
"Queue"="AlphaTest"
"IgnoreProjector"="True"
"RenderType"="Transparent"
}
LOD 300
// Shadow Pass : Adding the shadows (from Directional Light)
// by blending the light attenuation
Pass {
Blend SrcAlpha OneMinusSrcAlpha
Name "ShadowPass"
Tags {"LightMode" = "ForwardBase"}
CGPROGRAM
// Upgrade NOTE: excluded shader from DX11 and Xbox360; has structs without semantics (struct v2f members lightDir)
#pragma exclude_renderers d3d11 xbox360
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fwdbase
#include "UnityCG.cginc"
#include "AutoLight.cginc"
struct v2f {
float2 uv_MainTex : TEXCOORD0;
float4 pos : SV_POSITION;
LIGHTING_COORDS(3,4)
float3 lightDir;
};
float4 _MainTex_ST;
sampler2D _MainTex;
float _ShadowIntensity;
float _ShadowBlur;
v2f vert (appdata_full v){
v2f o;
o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex);
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.lightDir = ObjSpaceLightDir( v.vertex );
TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}
float4 frag (v2f i) : COLOR
{
float atten = LIGHT_ATTENUATION(i);
half4 c;
c.rgb = 0;
c.a = (1-atten) * _ShadowIntensity;
return c;
}
ENDCG
}
}
Fallback "VertexLit"
}
I would like to blur the result of this shader to simulate soft shadows, in order to have this kind of result :
I have read a lot about blur techniques shader. But it only blur the texture (like this link text).
But I don't achieve to blur the alpha part.
Any idea please?
Your answer
Follow this Question
Related Questions
Shader with zwrite, shadows and alpha (special alpha) 2 Answers
Shadows with Alpha, fade out shadow. 2 Answers
Is it possible to create a blur effect based on the alpha of a transparent texture on a plane? 0 Answers
Fade-In/Out shadows for a specific object 0 Answers
Semi-transparent shader with Shadows 3 Answers