Skip to content

Instantly share code, notes, and snippets.

@houkanshan
Last active December 4, 2015 14:27
Show Gist options
  • Save houkanshan/5bf781690dfcdc54b5aa to your computer and use it in GitHub Desktop.
Save houkanshan/5bf781690dfcdc54b5aa to your computer and use it in GitHub Desktop.
alpha_by_camera_distance.shader
Shader "Custom/Transparent/DiffuseRoad" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_MinDistance ("Min Distance", Float) = 3.2
_MaxDistance ("Max Distance", Float) = 4.0
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 200
ZWrite On
ColorMask 0
Blend SrcAlpha OneMinusSrcAlpha
Cull off
CGPROGRAM
#pragma surface surf Lambert alpha
sampler2D _MainTex;
fixed4 _Color;
float _MinDistance;
float _MaxDistance;
struct Input {
float2 uv_MainTex;
float3 worldPos;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
// o.Alpha = c.a * (1.0f - saturate((distance(IN.worldPos, _WorldSpaceCameraPos) - 0.1f) / 30.0f));
o.Alpha = c.a * (1.0f - saturate((distance(IN.worldPos, _WorldSpaceCameraPos) - _MinDistance)/(_MaxDistance - _MinDistance)));
}
ENDCG
}
Fallback "Transparent/VertexLit"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment