I’m trying to create a shader for a netting material, like this: http://media-cdn.tripadvisor.com/media/photo-s/01/4f/bf/41/langhorne.jpg
I don’t necessarily want a standard cut-out material, because it disappears in the distance. Fade and transparent are better, but still don’t give me enough control. So I started creating my own shader. Bear with me, this is the first shader I’m trying to create.
I pieced together a shader with a main texture and a bump map, smoothness, and metallic properties. Then I found a shader on the forum that adjusts the color based on distance. This is all a great start. What I’m missing is using the alpha channel of my main texture to give (semi-)transparency and then adjusting the alpha based on distance rather than the color (although I like being able to adjust the color, too). Here’s what I have:
Shader "Custom/FaderShader" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_BumpMap ("BumpMap", 2D) = "bump" {}
_MinColor ("Color in Minimal", Color) = (1, 1, 1, 1)
_MaxColor ("Color in Maximal", Color) = (0, 0, 0, 0)
_MinDistance ("Min Distance", Float) = 1
_MaxDistance ("Max Distance", Float) = 10
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader {
Tags { "RenderType"="Transparent" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
sampler2D _BumpMap;
struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
float3 worldPos;
};
float _MaxDistance;
float _MinDistance;
half4 _MinColor;
half4 _MaxColor;
half _Glossiness;
half _Metallic;
fixed4 _Color;
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
half4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
float dist = distance(_WorldSpaceCameraPos, IN.worldPos);
half weight = saturate( (dist - _MinDistance) / (_MaxDistance - _MinDistance) );
half4 distanceColor = lerp(_MinColor, _MaxColor, weight);
o.Albedo = c.rgb * distanceColor.rgb;
o.Alpha = c.a * distanceColor.a;
o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
}
ENDCG
}
FallBack "Diffuse"
}
