t1 / TFDContents / Assets / KinectDemos / VisualizerDemo / Shaders / HoloTriangles.shader @ 3
이력 | 보기 | 이력해설 | 다운로드 (4.02 KB)
1 |
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' |
---|---|
2 |
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' |
3 |
|
4 |
Shader "Custom/HoloTriangles" { |
5 |
Properties |
6 |
{ |
7 |
_Color("Main Color", Color) = (0.2, 0.5, 1.0) |
8 |
_Speed("Speed", Range(0.01, 10)) = 1 |
9 |
_TrianglesScale("Triangles Scale", Range(0.01, 10)) = 1 |
10 |
_RangeScale("Range Scale", Range(0.01, 10)) = 1 |
11 |
_Center("Center", Vector) = (0.0, -1.0, 3.0, 1.0) |
12 |
|
13 |
_MainTex ("Base (RGB)", 2D) = "white" {} |
14 |
} |
15 |
SubShader |
16 |
{ |
17 |
Tags{ "RenderType" = "Opaque" } |
18 |
Blend SrcAlpha OneMinusSrcAlpha |
19 |
LOD 100 |
20 |
|
21 |
Pass |
22 |
{ |
23 |
CGPROGRAM |
24 |
#pragma target 5.0 |
25 |
#pragma vertex vert |
26 |
#pragma fragment frag |
27 |
#include "UnityCG.cginc" |
28 |
|
29 |
#define pi 3.14159265358979 |
30 |
#define reciproce_sqrt3 0.57735026918962576450914878050196 |
31 |
|
32 |
half3 _Color; |
33 |
float _Speed; |
34 |
float _TrianglesScale; |
35 |
float _RangeScale; |
36 |
float4 _Center; |
37 |
|
38 |
sampler2D _MainTex; |
39 |
|
40 |
struct appdata |
41 |
{ |
42 |
float4 vertex : POSITION; |
43 |
float2 uv : TEXCOORD0; |
44 |
}; |
45 |
|
46 |
struct v2f |
47 |
{ |
48 |
float4 vertex : SV_POSITION; |
49 |
float4 world : TEXCOORD1; |
50 |
}; |
51 |
|
52 |
v2f vert(appdata v) |
53 |
{ |
54 |
v2f o; |
55 |
o.vertex = UnityObjectToClipPos(v.vertex); // UnityObjectToClipPos(v.vertex); |
56 |
o.world = mul(unity_ObjectToWorld, v.vertex); // mul(unity_ObjectToWorld, v.vertex); |
57 |
return o; |
58 |
} |
59 |
|
60 |
float planeDistance = 0.2; |
61 |
float offset; |
62 |
|
63 |
float r(float n) |
64 |
{ |
65 |
return frac(abs(sin(n*55.753)*367.34)); |
66 |
} |
67 |
|
68 |
float r(float2 n) |
69 |
{ |
70 |
return r(dot(n, float2(2.46, -1.21))); |
71 |
} |
72 |
|
73 |
float3 smallTrianglesColor(float3 pos) |
74 |
{ |
75 |
float a = (radians(60.0)); |
76 |
float zoom = 0.125; |
77 |
float2 c = (pos.xy + float2(0.0, pos.z)) * float2(sin(a), 1.0) / _TrianglesScale;//scaled coordinates |
78 |
c = ((c + float2(c.y, 0.0)*cos(a)) / zoom) + float2(floor((c.x - c.y*cos(a)) / zoom*4.0) / 4.0, 0.0);//Add rotations |
79 |
float type = (r(floor(c*4.0))*0.2 + r(floor(c*2.0))*0.3 + r(floor(c))*0.5);//Randomize type |
80 |
type += 0.3 * sin(_Time.y*5.0*type); |
81 |
|
82 |
float l = min(min((1.0 - (2.0 * abs(frac((c.x - c.y)*4.0) - 0.5))), |
83 |
(1.0 - (2.0 * abs(frac(c.y * 4.0) - 0.5)))), |
84 |
(1.0 - (2.0 * abs(frac(c.x * 4.0) - 0.5)))); |
85 |
l = smoothstep(0.06, 0.04, l); |
86 |
|
87 |
return lerp(type, l, 0.3); |
88 |
} |
89 |
|
90 |
float3 largeTrianglesColor(float3 pos) |
91 |
{ |
92 |
float a = (radians(60.0)); |
93 |
float zoom = 0.5; |
94 |
float2 c = (pos.xy + float2(0.0, pos.z)) * float2(sin(a), 1.0) / _TrianglesScale;//scaled coordinates |
95 |
c = ((c + float2(c.y, 0.0)*cos(a)) / zoom) + float2(floor((c.x - c.y*cos(a)) / zoom*4.0) / 4.0, 0.0);//Add rotations |
96 |
|
97 |
float l = min(min((1.0 - (2.0 * abs(frac((c.x - c.y)*4.0) - 0.5))), |
98 |
(1.0 - (2.0 * abs(frac(c.y * 4.0) - 0.5)))), |
99 |
(1.0 - (2.0 * abs(frac(c.x * 4.0) - 0.5)))); |
100 |
l = smoothstep(0.03, 0.02, l); |
101 |
|
102 |
return lerp(0.01, l, 1.0); |
103 |
} |
104 |
|
105 |
//--------------------------------------------------------------- |
106 |
// Material |
107 |
// |
108 |
// Defines the material (colors, shading, pattern, texturing) of the model |
109 |
// at every point based on its position and normal. In this case, it simply |
110 |
// returns a constant yellow color. |
111 |
//------------------------------------------------------------------------ |
112 |
float3 doMaterial(in float3 pos, in float3 midPos) |
113 |
{ |
114 |
float d = length(pos.xz - midPos.xz) + pos.y - midPos.y; |
115 |
d /= _RangeScale; |
116 |
float border = fmod(_Time.y * _Speed, 5.0); |
117 |
|
118 |
float3 c1 = largeTrianglesColor(pos); |
119 |
float3 c2 = smallTrianglesColor(pos); |
120 |
|
121 |
// Small rim |
122 |
float3 c = float3(1.0, 1.0, 1.0) * smoothstep(border - 0.2, border, d); |
123 |
// Large Triangles to all |
124 |
c += c1; |
125 |
// Small triangle slightly after front |
126 |
c += c2 * smoothstep(border - 0.4, border - 0.6, d); |
127 |
// Cutoff front |
128 |
c *= smoothstep(border, border - 0.05, d); |
129 |
// Cutoff back |
130 |
c *= smoothstep(border - 3.0, border - 0.5, d); |
131 |
// fade out |
132 |
c *= smoothstep(5.0, 4.0, border); |
133 |
|
134 |
return c *_Color; |
135 |
} |
136 |
|
137 |
fixed4 frag(v2f i) : SV_Target |
138 |
{ |
139 |
float3 c = doMaterial(i.world.xyz, _Center.xyz); |
140 |
return float4(c, length(c)); |
141 |
} |
142 |
ENDCG |
143 |
} |
144 |
} |
145 |
} |