Skip to content

Commit 1a437e6

Browse files
Grid shader
1 parent d2d12b6 commit 1a437e6

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

wireframe.shader

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//Shader uses screen-space partial derivatives, works the best with terrain meshes.
2+
3+
Shader "Wireframe"
4+
{
5+
Properties
6+
{
7+
[Header(Settings)] [Toggle] _transparency ("Transparency", Float) = 1
8+
}
9+
Subshader
10+
{
11+
Pass
12+
{
13+
Cull Off
14+
CGPROGRAM
15+
#pragma vertex vertex_shader
16+
#pragma fragment pixel_shader
17+
#pragma target 3.0
18+
19+
struct structure
20+
{
21+
float4 gl_Position : SV_POSITION;
22+
float3 vertex : TEXCOORD0;
23+
};
24+
25+
float _transparency;
26+
27+
structure vertex_shader (float4 vertex:POSITION)
28+
{
29+
structure vs;
30+
vs.gl_Position = UnityObjectToClipPos (vertex);
31+
vs.vertex = vertex;
32+
return vs;
33+
}
34+
35+
float4 pixel_shader (structure ps) : COLOR
36+
{
37+
float2 p = ps.vertex.xz;
38+
float2 g = abs(frac(p - 0.5) - 0.5) / fwidth(p);
39+
float s = min(g.x, g.y);
40+
float4 c = float4(s,s,s, 1.0);
41+
if (c.r<1.0)
42+
return 1.0-c;
43+
else
44+
{
45+
if (_transparency==1) discard;
46+
return 0;
47+
}
48+
}
49+
ENDCG
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)