Вот шейдер фога
Синтаксис:
Используется glsl
Shader "Custom/Fog" {
Properties{
_Color("Main Color", Color) = (1,1,1,1)
_MainTex("Base (RGB)", 2D) = "white" {} // Base (RGB)
}
SubShader{
Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" "LightMode" = "ForwardBase" "IgnoreProjector" = "True" }
Blend SrcAlpha OneMinusSrcAlpha
Lighting Off
LOD 200
Stencil{
Ref 1
Comp Greater
Pass Replace
}
CGPROGRAM
#pragma surface surf NoLighting noambient alpha:blend
fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, float aten) {
fixed4 color;
color.rgb = s.Albedo;
color.a = s.Alpha;
return color;
}
fixed4 _Color;
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
void surf(Input IN, inout SurfaceOutput o) {
half4 baseColor = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = _Color.rgb * baseColor.b;
o.Alpha = _Color.a - baseColor.g;
}
ENDCG
}
FallBack "Diffuse"
}
Properties{
_Color("Main Color", Color) = (1,1,1,1)
_MainTex("Base (RGB)", 2D) = "white" {} // Base (RGB)
}
SubShader{
Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" "LightMode" = "ForwardBase" "IgnoreProjector" = "True" }
Blend SrcAlpha OneMinusSrcAlpha
Lighting Off
LOD 200
Stencil{
Ref 1
Comp Greater
Pass Replace
}
CGPROGRAM
#pragma surface surf NoLighting noambient alpha:blend
fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, float aten) {
fixed4 color;
color.rgb = s.Albedo;
color.a = s.Alpha;
return color;
}
fixed4 _Color;
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
void surf(Input IN, inout SurfaceOutput o) {
half4 baseColor = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = _Color.rgb * baseColor.b;
o.Alpha = _Color.a - baseColor.g;
}
ENDCG
}
FallBack "Diffuse"
}
Но мне надо сделать затемнение объектов которые вылазят за границы фога.
Для них используется этот шейдер.
Синтаксис:
Используется glsl
Shader "Custom/Darken"
{
Properties
{
_Color("Main Color", Color) = (1,1,1,0)
[PreRenderData] _MainTex("Texture", 2D) = "white" {}
_Cutoff("Alpha cutoff", Range(0,1)) = 0.5
}
SubShader
{
Tags
{
"RenderType" = "Transparent"
"Queue" = "Transparent-1)"
"IgnoreProjector" = "True"
"CanUseSpriteAtlas" = "True"
}
Cull off
ZWrite off
Blend One OneMinusSrcColor
LOD 200
Stencil
{
Ref 1
Comp Always
Pass Replace
}
CGPROGRAM
#pragma surface surf Lambert alpha:blend
sampler2D _MainTex;
sampler2D _CutTex;
fixed4 _Color;
float _Cutoff;
struct Input {
float2 uv_MainTex;
};
void surf(Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) / _Color;
float ca = tex2D(_CutTex, IN.uv_MainTex).a;
o.Albedo = c.rgb;
if (ca > _Cutoff)
o.Alpha = c.a;
else
o.Alpha = 0;
}
ENDCG
}
Fallback "Transparent/VertexLit"
}
Но вокруг затемненного спрайта появляется прозрачная зона. Я нуб в шейдерах. Подскажите как её можно убрать?