forked from przemyslawzaworski/Unity3D-CG-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunlit_geometry_shader.shader
56 lines (51 loc) · 1.38 KB
/
unlit_geometry_shader.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
//For every input vertex, shader creates new primitive (blue quad from two triangles).
Shader "Unlit_Geometry_Shader"
{
SubShader
{
Pass
{
Cull Off
CGPROGRAM
#define UNITY_SHADER_NO_UPGRADE 1
#pragma target 4.0
#pragma vertex vertex_shader
#pragma geometry geometry_shader
#pragma fragment pixel_shader
struct custom_type
{
float4 pos : SV_POSITION;
};
custom_type vertex_shader(float4 vertex:POSITION)
{
custom_type vs ;
vs.pos = mul(unity_ObjectToWorld, vertex);
return vs;
}
[maxvertexcount(6)]
void geometry_shader(point custom_type input[1], inout TriangleStream<custom_type> stream)
{
custom_type gs;
float3 delta = float3 (0.25, 0.00, 0.00);
float4 vertices[6];
vertices[0] = float4(input[0].pos.xyz + delta.yyy, 1.0f);
vertices[1] = float4(input[0].pos.xyz + delta.yyx, 1.0f);
vertices[2] = float4(input[0].pos.xyz + delta.xyy, 1.0f);
vertices[3] = float4(input[0].pos.xyz + delta.xyx, 1.0f);
vertices[4] = float4(input[0].pos.xyz + delta.xyy, 1.0f);
vertices[5] = float4(input[0].pos.xyz + delta.yyx, 1.0f);
float4x4 m = mul(UNITY_MATRIX_MVP, unity_WorldToObject);
for (int i=0;i<6;i++)
{
gs.pos = mul(m, vertices[i]);
stream.Append(gs);
}
}
float4 pixel_shader(custom_type ps) : SV_TARGET
{
return float4(0.0,0.0,1.0,1.0);
}
ENDCG
}
}
}