Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
EyeballShader.cs
Go to the documentation of this file.
1using System;
5
7
9{
10 private struct Ring
11 {
12 public readonly Vector4 Color;
13
14 public readonly float Distance;
15
16 public Ring(Vector4 color, float distance)
17 {
18 Color = color;
19 Distance = distance;
20 }
21 }
22
23 private enum EyelidState
24 {
25 Closed,
26 Opening,
27 Open,
29 }
30
31 private static readonly Ring[] Rings = new Ring[5]
32 {
33 new Ring(Color.Black.ToVector4(), 0f),
34 new Ring(Color.Black.ToVector4(), 0.4f),
35 new Ring(new Color(17, 220, 237).ToVector4(), 0.5f),
36 new Ring(new Color(17, 120, 237).ToVector4(), 0.6f),
37 new Ring(Vector4.One, 0.65f)
38 };
39
40 private readonly Vector4 _eyelidColor = new Color(108, 110, 75).ToVector4();
41
42 private float _eyelidProgress;
43
45
47
48 private readonly UnifiedRandom _random = new UnifiedRandom();
49
50 private float _timeUntilPupilMove;
51
52 private float _eyelidStateTime;
53
54 private readonly bool _isSpawning;
55
57
58 public EyeballShader(bool isSpawning)
59 {
60 _isSpawning = isSpawning;
61 }
62
63 public override void Update(float elapsedTime)
64 {
65 UpdateEyelid(elapsedTime);
66 bool num = _timeUntilPupilMove <= 0f;
68 _timeUntilPupilMove -= elapsedTime;
69 if (num)
70 {
71 float num2 = (float)_random.NextDouble() * ((float)Math.PI * 2f);
72 float num3;
73 if (_isSpawning)
74 {
75 _timeUntilPupilMove = (float)_random.NextDouble() * 0.4f + 0.3f;
76 num3 = (float)_random.NextDouble() * 0.7f;
77 }
78 else
79 {
80 _timeUntilPupilMove = (float)_random.NextDouble() * 0.4f + 0.6f;
81 num3 = (float)_random.NextDouble() * 0.3f;
82 }
83 _targetOffset = new Vector2((float)Math.Cos(num2), (float)Math.Sin(num2)) * num3;
84 }
85 }
86
87 private void UpdateEyelid(float elapsedTime)
88 {
89 float num = 0.5f;
90 float num2 = 6f;
91 if (_isSpawning)
92 {
94 {
97 }
98 num = (float)NPC.MoonLordCountdown / (float)NPC.MaxMoonLordCountdown * 10f + 0.5f;
99 num2 = 2f;
100 }
101 _eyelidStateTime += elapsedTime;
102 switch (_eyelidState)
103 {
104 case EyelidState.Closed:
105 _eyelidProgress = 0f;
106 if (_eyelidStateTime > num)
107 {
108 _eyelidStateTime = 0f;
109 _eyelidState = EyelidState.Opening;
110 }
111 break;
112 case EyelidState.Opening:
114 if (_eyelidStateTime > 0.4f)
115 {
116 _eyelidStateTime = 0f;
118 }
119 break;
120 case EyelidState.Open:
121 _eyelidProgress = 1f;
122 if (_eyelidStateTime > num2)
123 {
124 _eyelidStateTime = 0f;
125 _eyelidState = EyelidState.Closing;
126 }
127 break;
128 case EyelidState.Closing:
129 _eyelidProgress = 1f - _eyelidStateTime / 0.4f;
130 if (_eyelidStateTime > 0.4f)
131 {
132 _eyelidStateTime = 0f;
133 _eyelidState = EyelidState.Closed;
134 }
135 break;
136 }
137 }
138
139 [RgbProcessor(/*Could not decode attribute arguments.*/)]
140 private void ProcessHighDetail(RgbDevice device, Fragment fragment, EffectDetailLevel quality, float time)
141 {
142 Vector2 vector = new Vector2(1.5f, 0.5f);
143 Vector2 vector2 = vector + _pupilOffset;
144 for (int i = 0; i < fragment.Count; i++)
145 {
146 Vector2 canvasPositionOfIndex = fragment.GetCanvasPositionOfIndex(i);
147 Vector2 vector3 = canvasPositionOfIndex - vector;
148 Vector4 vector4 = Vector4.One;
149 float num = (vector2 - canvasPositionOfIndex).Length();
150 for (int j = 1; j < Rings.Length; j++)
151 {
152 Ring ring = Rings[j];
153 Ring ring2 = Rings[j - 1];
154 if (num < ring.Distance)
155 {
156 vector4 = Vector4.Lerp(ring2.Color, ring.Color, (num - ring2.Distance) / (ring.Distance - ring2.Distance));
157 break;
158 }
159 }
160 float num2 = (float)Math.Sqrt(1f - 0.4f * vector3.Y * vector3.Y) * 5f;
161 float num3 = Math.Abs(vector3.X) - num2 * (1.1f * _eyelidProgress - 0.1f);
162 if (num3 > 0f)
163 {
164 vector4 = Vector4.Lerp(vector4, _eyelidColor, Math.Min(1f, num3 * 10f));
165 }
166 fragment.SetColor(i, vector4);
167 }
168 }
169}
void SetColor(int index, Vector4 color)
Definition Fragment.cs:97
Vector2 GetCanvasPositionOfIndex(int index)
Definition Fragment.cs:75
static double Cos(double d)
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static double Sqrt(double d)
static double Abs(double value)
static double Sin(double a)
const double PI
Definition Math.cs:16
void ProcessHighDetail(RgbDevice device, Fragment fragment, EffectDetailLevel quality, float time)
void UpdateEyelid(float elapsedTime)
override void Update(float elapsedTime)
static int MaxMoonLordCountdown
Definition NPC.cs:53
static int MoonLordCountdown
Definition NPC.cs:51
static Vector4 Lerp(Vector4 value1, Vector4 value2, float amount)
Definition Vector4.cs:277
Ring(Vector4 color, float distance)