Skip to content

Commit b1f08b4

Browse files
Wireframe ( Geometry shader version )
1 parent 87c1b35 commit b1f08b4

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

GeometryShaders/Wireframe.shader

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Shader "Wireframe (Geometry Shader)"
2+
{
3+
SubShader
4+
{
5+
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
6+
Pass
7+
{
8+
Blend SrcAlpha OneMinusSrcAlpha
9+
CGPROGRAM
10+
#pragma vertex VSMain
11+
#pragma geometry GSMain
12+
#pragma fragment PSMain
13+
#pragma target 5.0
14+
15+
struct Data
16+
{
17+
float4 vertex : SV_Position;
18+
float2 barycentric : BARYCENTRIC;
19+
};
20+
21+
void VSMain(inout float4 vertex:POSITION) { }
22+
23+
[maxvertexcount(3)]
24+
void GSMain( triangle float4 patch[3]:SV_Position, inout TriangleStream<Data> stream)
25+
{
26+
Data GS;
27+
for (uint i = 0; i < 3; i++)
28+
{
29+
GS.vertex = UnityObjectToClipPos(patch[i]);
30+
GS.barycentric = float2(fmod(i,2.0), step(2.0,i));
31+
stream.Append(GS);
32+
}
33+
stream.RestartStrip();
34+
}
35+
36+
float4 PSMain(Data PS) : SV_Target
37+
{
38+
float3 coord = float3(PS.barycentric, 1.0 - PS.barycentric.x - PS.barycentric.y);
39+
coord = smoothstep(fwidth(coord)*0.1, fwidth(coord)*0.1 + fwidth(coord), coord);
40+
return float4(0..xxx, 1.0 - min(coord.x, min(coord.y, coord.z)));
41+
}
42+
ENDCG
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)