Skip to content

Instantly share code, notes, and snippets.

@but80
Last active August 29, 2015 14:18
Show Gist options
  • Save but80/d5becd63a67b3a7a744b to your computer and use it in GitHub Desktop.
Save but80/d5becd63a67b3a7a744b to your computer and use it in GitHub Desktop.
Unity用 網シェーダ(単色・均一)
Shader "Custom/Net.shader" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
_NetColor ("Net Color", Color) = (0,0,0,1)
_NetPitch ("Net Pitch", Range(1,100)) = 6.0
_NetThickness ("Net Thickness", Range(0,1)) = 0.4
_NetOpacity ("Net Opacity", Range(0,1)) = 0.0
_NetBlur ("Net Blur", Range(0,1)) = 0.1
_NetDetailBlendNearZ ("Net Detail Blend Near Z" , Range(0,100)) = .5
_NetDetailBlendFarZ ("Net Detail Blend Far Z", Range(0,100)) = 10.0
}
SubShader {
Tags { "RenderType"="Opaque" }
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;
struct Input {
float2 uv_MainTex;
float3 viewDir;
float3 worldNormal;
float4 screenPos;
};
fixed4 _Color;
half _Glossiness;
half _Metallic;
fixed4 _NetColor;
half _NetPitch;
half _NetThickness;
half _NetOpacity;
half _NetBlur;
half _NetDetailBlendNearZ;
half _NetDetailBlendFarZ;
half inverselerp(half a, half b, half v) {
return (v-a) / (b-a);
}
half alpha2tone(half alpha, half pos) {
return saturate((alpha+_NetBlur-frac(pos)) / (2.0*_NetBlur));
}
half trifracxy(half x, half y) {
return sqrt( (1.0-abs(frac(x)*2.0-1.0)) * (1.0-abs(frac(y)*2.0-1.0)) );
}
half easing_outin(half v) {
v = v*2.0 - 1.0;
v = sign(v) * sqrt(abs(v));
return .5 + v * .5;
}
half easing_inout(half v) {
v = v*2.0 - 1.0;
v = sign(v) * v*v;
return .5 + v * .5;
}
half sqlerp(half a, half b, half w) {
return sqrt(lerp(a*a, b*b, w));
}
void surf (Input IN, inout SurfaceOutputStandard o) {
half cos_ = length(dot(-normalize(IN.viewDir), normalize(IN.worldNormal)));
half alpha = saturate(_NetOpacity * (1.0f - _NetThickness) + _NetThickness / cos_);
half d = IN.screenPos.z + _ProjectionParams.y;
half toneRatio = saturate(inverselerp(_NetDetailBlendNearZ, _NetDetailBlendFarZ, d));
half sx = IN.screenPos.x / IN.screenPos.w * _ScreenParams.x;
half sy = IN.screenPos.y / IN.screenPos.w * _ScreenParams.y;
half pitch = _NetPitch / d;
half pitchl2 = log2(pitch);
half pitch0 = pow(2, floor(pitchl2));
half blend1 = frac(pitchl2);
blend1 = easing_inout(blend1);
half ax = (sx+sy) / pitch0;
half ay = (sx+_ScreenParams.y-sy) / pitch0;
half a = lerp(trifracxy(ax, ay), trifracxy(ax/2.0, ay/2.0), blend1);
a = alpha2tone(alpha, a);
a = sqlerp(a, alpha, toneRatio);
fixed4 color_ = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = lerp(color_.rgb, _NetColor, a);
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = color_.a;
}
ENDCG
}
FallBack "Diffuse"
}
@but80
Copy link
Author

but80 commented Apr 10, 2015

FXAA3と相性が悪く、変なムラが出る。SSAAは大丈夫っぽい

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment