I'm having a problem. I have a doubble sided shader for my trees in Unity and they look fine sometimes but in our game scene they are glowing like crazy. i copied this shader for them but i don´t know if the problem is the shader or the ligt. what can I do?
We only have a directional light in the scene
Shader:
Shader "Custom/Standard Two Sided Soft Blend" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
[NoScaleOffset] _MainTex ("Albedo (RGB)", 2D) = "white" {}
[Toggle] _UseMetallicMap ("Use Metallic Map", Float) = 0.0
[NoScaleOffset] _MetallicGlossMap("Metallic", 2D) = "black" {}
[Gamma] _Metallic ("Metallic", Range(0,1)) = 0.0
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_BumpScale("Scale", Float) = 1.0
[NoScaleOffset] _BumpMap("Normal Map", 2D) = "bump" {}
_Cutoff("Alpha Cutoff", Range(0.01,1)) = 0.5
}
SubShader {
Tags { "Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout" }
Blend SrcAlpha OneMinusSrcAlpha
LOD 200
ZWrite Off
Cull Off
Pass {
ColorMask 0
ZWrite On
CGPROGRAM
struct v2f {
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
sampler2D _MainTex;
fixed _Cutoff;
v2f vert (appdata_img v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.texcoord = v.texcoord;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.texcoord);
clip(col.a - _Cutoff);
return 0;
}
ENDCG
}
Pass
{
Tags {"LightMode"="ShadowCaster"}
ZWrite On
Cull Off
CGPROGRAM
struct v2f {
V2F_SHADOW_CASTER;
float2 texcoord : TEXCOORD1;
};
v2f vert(appdata_base v)
{
v2f o;
TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
o.texcoord = v.texcoord;
return o;
}
sampler2D _MainTex;
fixed _Cutoff;
float4 frag(v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.texcoord);
clip(col.a - _Cutoff);
SHADOW_CASTER_FRAGMENT(i)
}
ENDCG
}
CGPROGRAM
#pragma surface surf Standard fullforwardshadows alpha:fade nolightmap
#pragma shader_feature _USEMETALLICMAP_ON
sampler2D _MainTex;
sampler2D _MetallicGlossMap;
sampler2D _BumpMap;
struct Input {
float2 uv_MainTex;
fixed facing : VFACE;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
half _BumpScale;
fixed _Cutoff;
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
fixed4 mg = tex2D(_MetallicGlossMap, IN.uv_MainTex);
o.Metallic = mg.r;
o.Smoothness = mg.a;
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
// Rescales the alpha on the blended pass
o.Alpha = saturate(c.a / _Cutoff);
o.Normal = UnpackScaleNormal(tex2D(_BumpMap, IN.uv_MainTex), _BumpScale);
if (IN.facing < 0.5)
o.Normal *= -1.0;
}
ENDCG
}
FallBack "Diffuse"
}
Replies
I would apply just a standard unity shader with you alpha texture and see if it resolves the issue, this way we can leave out texture messing things up. Ignore two side stuff for this test too.
Also if you are using opacity anyways why make a custom shader just got with default one with two side geometry option enabled in object properties.