-
Notifications
You must be signed in to change notification settings - Fork 26
/
Stipple.shader
58 lines (46 loc) · 1.53 KB
/
Stipple.shader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Diffuse shader with stipple cutoff effect
Shader "Game/Diffuse Transparent Stipple" {
Properties {
_MainTex("Base (RGB)", 2D) = "white" { }
}
SubShader {
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Lambert addshadow
sampler2D _MainTex;
static const float4x4 kThresholdMatrix = {
1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0,
13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0,
4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0,
16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0
};
static const float4x4 kKernelMatrix = {
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
};
// Cull distances in world units (from the camera)
static const float kCullDistanceStart = 7;
static const float kCullDistanceEnd = 8;
struct Input {
float2 uv_MainTex;
float4 screenPos;
float3 worldPos;
};
void surf(Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
// Unproject the screen pixel coordiante
float2 pos = IN.screenPos.xy / IN.screenPos.w;
pos *= _ScreenParams.xy;
// Clip pixel within [start, end] distance from camera
float worldDist = distance(_WorldSpaceCameraPos, IN.worldPos.xyz);
float interpDist = 1.0 - smoothstep(kCullDistanceStart, kCullDistanceEnd, worldDist);
clip(interpDist - kThresholdMatrix[fmod(pos.x, 4)] * kKernelMatrix[fmod(pos.y, 4)]);
}
ENDCG
}
Fallback "Transparent/Cutout/VertexLit"
}