forked from przemyslawzaworski/Unity3D-CG-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VertexShaderImage.shader
54 lines (48 loc) · 1.31 KB
/
VertexShaderImage.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
Shader "Vertex Shader Image"
{
Subshader
{
Pass
{
Cull Off
CGPROGRAM
#pragma vertex VSMain
#pragma fragment PSMain
#pragma target 5.0
float2 PolarToCartesian (float2 p)
{
return p.x * float2(cos(p.y),sin(p.y));
}
float2 CartesianToPolar (float2 p)
{
return float2(length(p), atan2(p.y, p.x));
}
float3 Pattern (float2 uv)
{
uv = CartesianToPolar (abs(uv));
uv = (12.0*uv);
uv = PolarToCartesian(uv);
return float3(4.0/abs(uv),uv.x/uv.y);
}
float4 VSMain (uint id:SV_VertexID, out float3 color:TEXCOORD0) : SV_POSITION
{
float q = floor(float(id) / 6.0);
float px = fmod(float(id), 2.0);
float py = (float(id)-6.0 * floor(float(id)/6.0)) + 6.0;
py = sign(126.0-py*floor(126.0/py));
float3 center = float3(fmod(q,1024.0), 0.0, floor(q/1024.0));
float error = 0.0000001;
float2 uv = float2(center.x / 1024.0, center.z / 1024.0) + error;
uv = float2(2.0*uv-1.0);
color = Pattern(uv);
float scale = 0.1;
return UnityObjectToClipPos(float4(float3(sign(px)-0.5, 0.0, sign(py)-0.5) * scale + center * scale, 1.0));
}
float4 PSMain (float4 vertex:SV_POSITION, float3 color:TEXCOORD0) : SV_Target
{
return float4(color, 1.0);
}
ENDCG
}
}
}