- Home /
Question by
ThisGuyThatsHere · Jun 15, 2017 at 08:42 PM ·
shaderalphatransparentvertex shadercutoff
Shader bug or code fault?
Hey, so I've got this weird problem, here is how my shader looks:
but for some reason, based on camera rotation (and position!, for example it doesn't happen on Y=0 in a short radius around center) it becomes this:
I just don't understand the problem here, code:
Shader "Environment/Leaves"
{
Properties
{
_Tex ("Texture", 2D) = "white" {}
_LightingTex ("Lighting Texture |R|", 2D) = "white" {}
_LightingMult ("Lighting Multiplier", Float) = 1.0
_Color ("Tint", Color) = (1,1,1,1)
_Cutoff ("Alpha Cutoff", Range(0,1)) = 0.1
}
SubShader
{
Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
#include "UnityLightingCommon.cginc"
#pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight
#include "AutoLight.cginc"
struct appdata
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
SHADOW_COORDS(1)
fixed3 diffDef : COLOR0;
fixed3 diffRev : COLOR1;
float4 pos : SV_POSITION;
};
sampler2D _Tex;
sampler2D _LightingTex;
float4 _Tex_ST;
v2f vert (appdata v)
{
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord;
half3 worldNormal = UnityObjectToWorldNormal(v.normal);
half nlDef = max(0, dot(worldNormal, _WorldSpaceLightPos0.xyz));
half nlRev = max(0, dot(worldNormal * -1.0, _WorldSpaceLightPos0.xyz));
o.diffDef = nlDef * _LightColor0;
o.diffRev = nlRev * _LightColor0;
TRANSFER_SHADOW(o)
return o;
}
fixed4 _Color;
float _Cutoff;
float _LightingMult;
float sum3 (fixed3 v) {
return v.x + v.y + v.z;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_Tex, i.uv);
fixed4 lightOcc = tex2D(_LightingTex, i.uv) * _LightingMult;
clip(col.a - _Cutoff);
fixed shadow = SHADOW_ATTENUATION(i);
fixed3 light;
if(sum3(i.diffDef) > sum3(i.diffRev)) {
light = i.diffDef * shadow;
} else {
light = i.diffRev * shadow;
}
col.rgb *= light;
col += lightOcc;
col *= _Color;
return col;
}
ENDCG
}
// Simple shadow pass
Pass
{
Tags {"LightMode"="ShadowCaster"}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_shadowcaster
#include "UnityCG.cginc"
struct v2f {
float2 uv : TEXCOORD0;
V2F_SHADOW_CASTER;
};
sampler2D _Tex;
v2f vert(appdata_base v)
{
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
v2f o;
o.uv = v.texcoord;
TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
return o;
}
float _Cutoff;
float4 frag(v2f i) : SV_Target
{
fixed4 col = tex2D(_Tex, i.uv);
clip(col.a - _Cutoff);
SHADOW_CASTER_FRAGMENT(i)
}
ENDCG
}
}
}
Comment
Best Answer
Answer by ThisGuyThatsHere · Jun 16, 2017 at 08:45 AM
Nevermind, the problem was kind of stupid, but if anyone has similar problem, dont forget:
Tags {"LightMode"="ForwardBase"}