Такая проблема, использую VertexLit rendering path, что бы повысить быстродействие. Под это дело необходим AlphaTest шейдер. Из родных - работает только Unlit/Transparent Cutout, но он не подходит, так как на освещение ему плевать.
Попытался написать свой шейдер, Diffuse + Transparent cutout.
В итоге проблема такая, вместо скайбоксовской текстуры, прозрачность выводит solid color камеры.
На остальных объектах прозрачность работает как надо.
Не совсем понимаю как это решать.
Синтаксис:
Используется csharp
Shader "Custom/DiffuseCutoff" {
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex("Main Texture", 2D) = "white" {}
_SecondTex("AlfaMAsk", 2D) = "white" {}
_Cutoff("Cutoff", Range(0,1)) = 0.5
}
SubShader
{
Pass
{
Tags{ "Queue" = "AlphaTest" "LightMode" = "Vertex" "RenderType"="TransparentCutout" "IgnoreProjector"="True"}
Cull Off
//ZWrite On
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "UnityLightingCommon.cginc"
fixed4 _Color;
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _SecondTex;
float4 _SecondTex_ST;
fixed _Cutoff;
struct v2f
{
float2 uv : TEXCOORD0;
float2 uv1 : TEXCOORD1;
fixed4 diff : COLOR0;
float4 vertex : SV_POSITION;
};
v2f vert(appdata_base v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
o.uv1 = TRANSFORM_TEX(v.texcoord, _SecondTex);
half3 worldNormal = UnityObjectToWorldNormal(v.normal);
half nl = max(0, dot(worldNormal, _WorldSpaceLightPos0.xyz));
o.diff = nl * _LightColor0;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
col *= i.diff * _Color;
fixed4 alfaColor = tex2D(_SecondTex, i.uv1);
if(alfaColor.a > _Cutoff)
col = fixed4(col.r, col.g, col.b, 1.0);
else
col = fixed4(col.r, col.g, col.b, 0.0);
return col;
}
ENDCG
}
}
}
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex("Main Texture", 2D) = "white" {}
_SecondTex("AlfaMAsk", 2D) = "white" {}
_Cutoff("Cutoff", Range(0,1)) = 0.5
}
SubShader
{
Pass
{
Tags{ "Queue" = "AlphaTest" "LightMode" = "Vertex" "RenderType"="TransparentCutout" "IgnoreProjector"="True"}
Cull Off
//ZWrite On
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "UnityLightingCommon.cginc"
fixed4 _Color;
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _SecondTex;
float4 _SecondTex_ST;
fixed _Cutoff;
struct v2f
{
float2 uv : TEXCOORD0;
float2 uv1 : TEXCOORD1;
fixed4 diff : COLOR0;
float4 vertex : SV_POSITION;
};
v2f vert(appdata_base v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
o.uv1 = TRANSFORM_TEX(v.texcoord, _SecondTex);
half3 worldNormal = UnityObjectToWorldNormal(v.normal);
half nl = max(0, dot(worldNormal, _WorldSpaceLightPos0.xyz));
o.diff = nl * _LightColor0;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
col *= i.diff * _Color;
fixed4 alfaColor = tex2D(_SecondTex, i.uv1);
if(alfaColor.a > _Cutoff)
col = fixed4(col.r, col.g, col.b, 1.0);
else
col = fixed4(col.r, col.g, col.b, 0.0);
return col;
}
ENDCG
}
}
}